我在尝试使用codeigniter发送电子邮件时遇到错误。我已经在一个在线服务器上测试了我正在使用的功能,但它仍然会抛出同样的错误。
以下是我的功能:
//send email
function sendEmail() {
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'email', // change it to yours
'smtp_pass' => 'pswd', // change it to yours
'mailtype' => 'html',
'charset' => 'iso-8859-1',
'wordwrap' => TRUE
);
$message = 'Test message';
$this->load->library('email', $config);
$this->email->set_newline("'r'n");
$this->email->from('zzz@gmail.com'); // change it to yours
$this->email->to('xxx@gmail.com'); // change it to yours
$this->email->subject('Resume from JobsBuddy for your Job posting');
$this->email->message($message);
if ($this->email->send()) {
echo 'Email sent.';
} else {
show_error($this->email->print_debugger());
}
}
我得到以下错误:
无法验证密码。错误:534-5.7.14请通过登录然后重试。534-5.7.14了解更多534 5.7.14https://support.google.com/mail/answer/78754w84sm8590284ioi.20-gsmtp无法使用PHP SMTP发送电子邮件。你的服务器可能未配置为使用此方法发送邮件。
请协助
答案与代码无关,但因为必须启用Gmail帐户才能允许smtp/IMAP访问。来自谷歌帮助中心:
- 登录Gmail网络界面
- 打开"设置"页面上的"转发和POP/IMAP"选项卡,然后配置IMAP或POP
- 在Gmail中启用此功能后,请确保单击"保存更改",以便Gmail可以与您的邮件客户端通信