PEAR Mail无法发送邮件,但也没有报错信息。

4

我正在尝试使用PEAR Mail通过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!";

而且,如果不使用try catch,仅仅使用...
if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
echo("<p>Message successfully sent!</p>");
}

在这两种情况下,页面都会显示“电子邮件发送成功!”,但是邮件并没有到达。如果我故意输入错误的用户名和密码或虚构的邮件服务器,就不会报错。
在这种情况下,我该如何检查错误,为什么脚本仍然会运行,即使我给它一个明显的错误?
谢谢 Greg

1
邮件日志显示了什么? - user557846
你是指邮件服务器的错误日志还是其他什么?我无法访问邮件服务器日志。 - Barbs
1个回答

8

Dagon,

感谢您指引我正确的方向。在进一步搜索后,我找到了如何设置$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);

这将显示邮件连接的响应以及所有发送到邮件服务器进行调试的内容。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接