我尝试使用xampp从我的localhost发送电子邮件到使用Codeigniter的Gmail。
这是我在控制器中的代码:
public function mail()
{
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'smtp.gmail.com',
'smtp_port' => 465,
'smtp_user' => 'kingkangddg@gmail.com',
'smtp_pass' => '*****',
'new_line' => "\r\n",
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from('kingkangddg@gmail.com', 'Glenn Samporna');
$this->email->to('fajardokarlelbert@gmail.com');
$this->email->subject('Test');
$this->email->message('sample message');
if($this->email->send()){
echo 'sent';
} else {
show_error($this->email->print_debugger());
}
}
它会抛出这样的错误:
hello: F
The following SMTP error was encountered: F
Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.
Date: Mon, 29 Jan 2018 09:35:37 +0100
From: "King Kang" <kingkangddg@gmail.com>
Return-Path: <kingkangddg@gmail.com>
To: fajardokarlelbert@gmail.com
Subject: =?UTF-8?Q?Test?=
Reply-To: <kingkangddg@gmail.com>
User-Agent: CodeIgniter
X-Sender: kingkangddg@gmail.com
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: <5a6edcd99171d@gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
sample message
遇到PHP错误
严重程度:通知
消息:fwrite():发送6个字节失败,errno = 10053 An 建立的连接被主机中的软件中止 机。
文件名:libraries / Email.php
行号:2242
Backtrace:
我希望你能帮我解决这个问题。
答案 0 :(得分:0)
在我当地测试并正常工作。
更改
new_line
<强> Check My answer to another question how to configure mail setting in xampp 强>
检查php.ini是否存在此路径
sendmail_path /usr/sbin/sendmail -t -i /usr/sbin/sendmail -t -i
<强>代码强>
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'smtp.gmail.com',
'smtp_port' => 587,
'smtp_crypto' => 'tls',
'smtp_user' => 'kingkangddg@gmail.com',
'smtp_pass' => '*****',
);
确保:关闭双向身份验证并允许第三方访问