我在通过SMTP协议发送邮件时遇到问题。
Welcome.php
$this->load->library('email');
$config = array();
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'smtp.zoho.com';
$config['smtp_user'] = 'support@domain.com';
$config['smtp_pass'] = '**************';
$config['smtp_port'] = 465;
$config["smtp_crypto"] = "ssl";
$this->email->initialize($config);
$this->email->set_newline("\r\n");
$this->email->from('support@domain.com', 'Support name'); // change it to yours
$this->email->to($to);// change it to yours
$this->email->subject($subject);
$this->email->message($message);
if($this->email->send())
{
echo "Success! - An email has been sent to ".$to;
}
else
{
show_error($this->email->print_debugger());
return false;
}
}
以下是输出错误:
An Error Was Encountered
220 mx.zohomail.com SMTP Server ready June 29, 2018 5:16:40 AM PDT
hello:
The following SMTP error was encountered:
Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.
Date: Fri, 29 Jun 2018 12:16:40 +0000
From: "Support Name" <support@domain.com>
Return-Path: <support@domain.com>
To: recipent@gmail.com
Subject: =?ISO-8859-1?Q?=43=6F=70=79=20=61=6C=6C=20=74=68=65?=
Reply-To: <support@domain.com>
User-Agent: CodeIgniter
X-Sender: support@domain.com
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: <5b36232840595@domain.com>
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary="B_ALT_5b3623284061c"
This is a multi-part message in MIME format.
Your email application may not support this format.
--B_ALT_5b3623284061c
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
Some
--B_ALT_5b3623284061c
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Some Email Description=0A=0A Some Email Description
--B_ALT_5b3623284061c--
注意:该脚本在localhost以及多个 其他主机,但不能在VPS主机上使用。
这些是要记住的事情:
$config['protocol'] = "smtp";
更改为$config['protocol'] = "sendmail";
是可行的。但是我只想通过SMTP协议发送邮件。 答案 0 :(得分:0)
我希望这段代码能正常工作
$Config = [
'protocol' => 'smtp',
'smtp_host' => 'smtp.zoho.com',
'smtp_port' => 465,
'smtp_user' => 'support@domain.com',
'smtp_pass' => '**************',
'mailtype' => 'html',
'charset' => 'utf-8'
];
$this->load->library('email',$config);
$this->email->set_newline("\r\n");
$this->email->from('support@domain.com', 'Support name'); // change it to yours
$this->email->to($to);// change it to yours
$this->email->subject($subject);
$this->email->message($message);
if($this->email->send()){
echo "Success! - An email has been sent to ".$to;
}
else{
show_error($this->email->print_debugger());
return false;
}
答案 1 :(得分:0)
解决方案: 问题已已修复!罪魁祸首是有效主机名和反向DNS 。
详细信息:
由于配置错误,SMTP在7 - 10 secs
附近响应。根据{{3}},如果我们不指定smtp_timeout
,它将采用默认值5 sec
。
因此,我将smtp_timeout
从默认的5 sec
更改为10 sec
,并且有效。
找出问题所在后,发现SMTP响应速度很慢。没有添加有效的主机名,反向DNS 。因此添加。现在它正在按预期工作。现在,我删除了smtp_timeout
字段。现在正在工作。