我想使用 codeigniter 发送电子邮件,我看看如何在互联网上做到这一点。但是当我编写代码时,电子邮件不会发送给人们。
使用 codeigniter 3.1.10
private function _sendEmail(){
$config = [
'mailtype' => 'html',
'charset' => 'utf-8',
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.gmail.com',
'smtp_user' => '****',
'smtp_pass' => '****',
'smtp_port' => 465,
'crlf' => "\r\n"
];
$this->load->library('email',$config);
$this->email->from('[email protected]','VCO Padang Pariaman');
$this->email->to('[email protected]');
$this->email->subject('Testing');
$this->email->message("hallo");
if($this->email->send()){
return true;
}else {
echo $this->email->print_debugger();
}
}
我想发送电子邮件至 [email protected]
这可能是因为 SMTP 身份验证中给出的用户名和密码错误,或者邮件服务器防火墙阻止了 SMTP 端口。
如果您使用的是 Gmail 帐户,请检查此链接并关闭“允许安全性较低的应用程序”。
这是网址:https : //myaccount.google.com/lesssecureapps
然后尝试再次发送电子邮件。
我已更新您的代码并立即检查:
private function _sendEmail() {
$config = [
'mailtype' => 'html',
'charset' => 'utf-8',
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.gmail.com',
'smtp_user' => '****',
'smtp_pass' => '****',
'smtp_port' => '465',
'smtp_timeout' => '20',
'validation' => TRUE,
'newline' => "\r\n"
];
$this->load->library('email', $config);
$this->email->initialize($config);
$this->email->from('[email protected]', 'VCO Padang Pariaman');
$this->email->to('[email protected]');
$this->email->subject('Testing');
$this->email->message("hallo");
if ($this->email->send()) {
return true;
} else {
echo $this->email->print_debugger();
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句