【发布时间】:2026-02-10 03:00:02
【问题描述】:
在我将源上传到托管服务器后,电子邮件发送不起作用,我的代码如下:
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'所有[失败]
3 - 更改 'smtp_port' => 587 或 'smtp_port' => 25 [FAILED]
4 - 在我的谷歌电子邮件中,我允许 Less Secure Apps ,Disabled 2 Step Verification [FAILED]
5 - 评论/删除 $config 变量 [SUCCESS] 但电子邮件被发送到垃圾邮件,并带有以下黄色背景警告
This message may not have been sent by: isecvr@gmail.com
请建议我该怎么做,我现在尝试发送电子邮件超过 10 个小时。
【问题讨论】:
-
没什么,我的文件在实时托管服务器上,在 xampp 代码中工作正常,但现在不是
-
OK 只需检查一下您的控制器文件,您是否确保只有第一个字母大写,如
Example.php和class Example extends CI_Controller {},CI3 版本是必须的。可能是您的提供商有问题? -
是的 @wolfgang1983 这是我的班级名称,看起来像
User extends REST_Controller -
和文件名User.php
-
是的,文件名是 User.php @wolfgang1983
标签: php codeigniter email ssl smtp