在我将源代码上传到托管服务器后,电子邮件发送不起作用,我的代码如下:
function sendMail($code,$email)
{
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.gmail.com',
'smtp_port' => 465,
'smtp_user' => 'something@gmail.com',
'smtp_pass' => 'something',
'smtp_timeout' => '4',
'mailtype' => 'text',
'charset' => 'utf-8'//'iso-8859-1'
);
$message = 'Your Verification code is :'.$code;
$this->load->library('email',$config);
$this->email->set_newline("\r\n");
$this->email->from('isecvr@gmail.com',"iSec Community"); // change it to yours
$this->email->to($email);// change it to yours
$this->email->subject('Activate your account');
$this->email->message($message);
if($this->email->send())
{
return true;
}
else
{
show_error($this->email->print_debugger());
return false;
}
}
我尝试使这项工作成功,有些成功了,但它们被发送到垃圾邮件而不是收件箱,有些根本不起作用:
1 - 更改 'protocol' => 'sendmail'
[FAILED]
2 - 更改 'smtp_host' => 'smtp.gmail.com'
或
'smtp_host' => 'ssl://smtp.gmail.com'
或
'smtp_host' => 'ssl://smtp.googlemail.com'
或
'smtp_host' => 'smtp.googlemail.com'
所有[FAILED]
3 - 更改 'smtp_port' => 587
或 'smtp_port' => 25
[FAILED]
4 - 在我的谷歌电子邮件中,我允许不太安全的应用
,禁用两步验证
[FAILED]
5 - 评论/删除 $config
变量 [SUCCESS] 但电子邮件被发送到 SPAMS 并带有以下黄色背景警告
此消息可能不是由 isecvr@gmail.com 发送的
请建议我该怎么做,我现在尝试发送电子邮件超过 10 个小时。
最佳答案
可能是您的服务器不允许与 gmail 服务器通信?这可能是其中一种可能。如果不是这种情况,那么“show_error($this->email->print_debugger());”的输出是什么?您一定会从此行获得一些输出。
关于php - 从托管服务器使用 CodeIgniter 发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38715915/