我正在尝试使用PEAR邮件通过PHP发送电子邮件,但是虽然页面报告邮件已经发送,但它从未到达(我将其发送给自己进行测试).
我一直在研究如何处理错误,如果我转向严格的报告,我会得到大约六个这样的报告:
Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in Blah Blah Blah! on line 450
Strict Standards: Non-static method PEAR::raiseerror() should not be called statically, assuming $this from incompatible context in Blah Blah Blah! on line 451
在我的阅读中,我被告知这些错误并不能阻止脚本成功,并且大多数人只是关闭严格的报告,但在我的情况下,脚本不起作用.
try {
$host = "ssl://mail.example.com";
$port = 25;
$auth = true; // turn on SMTP authentication
$username = "name@example.com"; // SMTP username
$password = "password"; // SMTP password
$mail = Mail::factory('smtp',
array('host'=>$host,'port'=>$port,'auth'=>true,'username'=>$username,'password'=>$password));
$mail->send($to,$headers,$message);
} catch (Exception $e) {
echo "Exception: " . $e->getMessage();
}
echo "Message Successfully Sent!";
而且没有尝试捕获并只是使用…
if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
echo("<p>Message successfully sent!</p>");
}
在这两种情况下,页面报告“电子邮件已成功发送!”但邮件没有到达.如果我故意输入错误的用户名和密码或虚构的邮件服务器,则不会报告错误.
在这种情况下如何进行错误检查?如果我给它一个明显的错误,为什么脚本仍会运行?
谢谢
格雷格
解决方法:
衮,
谢谢你指点我正确的方向.在进一步搜索后,我发现如何设置$params [‘debug’]并引导我找到问题的根源.
$params = array('debug'=>true,'host'=>$host,'port'=>$port,'auth'=>true,'username'=>$username,'password'=>$password);
$mail = Mail::factory('smtp', $params);
$mail->send($to,$headers,$message);