我一直在尝试使用PHP从我的网站发送电子邮件。但是,我无法做到,并且不断收到此错误Unable to send email using PHP mail(). Your server might not be configured to send mail using this method.
,过去一年来php电子邮件配置一直运行良好,直到最近我才开始收到此错误。
我在配置中包含了smtp设置,以前没有,但是仍然出现相同的错误。
我已经遍历了StackOverFlow中提供的有关错误的解决方案,但似乎没有一个对我有用。
我尝试使用不同的smtp ports(25,465,587)
,但似乎没有任何效果。
我尝试了不同的smtp_crypto(ssl,tls,null)
,但没有一个对我有用。
我在代码中加入了行set_newline("\r\n")
,我也删除了该行,但错误仍然存在。
我什至与我的网络托管服务提供商联系,但通知我问题不在他们一方。
我发送电子邮件的代码如下所示
class EmailController extends CI_Controller {
public function __construct() {
parent:: __construct();
$this->load->helper('url');
$this->load->library('email');
}
function send() {
$config = Array(
'protocol' => 'mail',
'smtp_host' => 'mail.(domain_name)',
'smtp_port' => '465',
'smtp_user' => '********',
'smtp_pass' => '*********',
'mailtype' => 'html',
'charset' => 'utf-8'
);
$this->email->initialize($config);
$this->email->set_newline("\r\n");
$email_body ="<div>hello world</div>";
$this->email->from('info@myemail.com');
$this->email->to($to);
$this->email->subject($subject);
$this->email->message($message);
if ($this->email->send()) {
echo 'Your Email has successfully been sent.';
} else {
show_error($this->email->print_debugger());
}
}
}
我希望输出为消息“您的电子邮件已成功发送”和一封电子邮件,但我不断收到以下错误消息;
Unable to send email using PHP mail(). Your server might not be configured to send mail using this method.
Date: Date and time stamp
From: <info@myemail.com>
Return-Path: <info@myemail.com>
Reply-To: <info@myemail.com>
User-Agent: CodeIgniter
X-Sender: info@myemail.com
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: <5d234afb2e34a@myemail.com>
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary="B_ALT_5d234afb2e38e"
=?UTF-8?Q?Orders=20not=20being=20sent?=
This is a multi-part message in MIME format.
Your email application may not support this format.
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
My Order
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
My Order
我该如何解决?