我使用此代码从localhost发送电子邮件。它在代码Igniter中。我的操作系统是Ubuntu 14.7X
function email()
{
$config = array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => '*****@gmail.com', // change it to yours
'smtp_pass' => '*****', // change it to yours
'mailtype' => 'html',
'charset' => 'UTF-8',
);
$message = 'aggasdgsd';
$this->load->library('email', $config);
$this->email->set_newline("'r'n");
$this->email->from('*****@gmail.com'); // change it to yours
$this->email->to('****@gmail.com');// change it to yours
$this->email->subject('Rdfgsdfgf ing');
$this->email->message($message);
if($this->email->send())
{
echo 'Email sent.';
}
else
{
show_error($this->email->print_debugger());
}
}
当我使用URL http://localhost/ci_project/email
时发送电子邮件,但是如果我使用URL http://10.10.10.XX/ci_project/email
,它就不起作用,而且没有错误消息。
有什么想法吗,为什么在URL&当我在URL中使用IP地址时不工作??
检查服务器上是否有电子邮件服务器在工作。如果您正在使用sendmail,请在服务器上尝试此命令服务发送邮件重新启动
您的PHP配置是否启用ssl?检查php.ini 中是否有以下行
extension=php_openssl.dll