PHP PEAR 邮件错误
我在尝试发送电子邮件时收到以下代码错误。它可以在我的本地计算机上运行,但当我将其放在我的 AWS LAMP 服务器上时则无法运行。我无法调试任何内容,因为运行脚本时收到 HTTP 500 错误。不过,我知道 PEAR 已安装。
代码:
require_once "Mail.php";
$from = "Email<[email protected]>";
$to = "[email protected]";
$subject = "ERROR REPORT";
$body = "test message";
$host = "ssl://smtp.gmail.com";
$port = "465";
$username = "[email protected]";
$password = "pass1";
$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'port' => $port,
'auth' => true,
'username' => $username,
'password' => $password));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
echo("Error message sent!");
}
上面的 send() 命令似乎出现问题。关于如何更好地调试这个问题有什么建议吗?
I'm getting an error with the following code when trying to send an email. It works on my local machine but not when I put it on my AWS LAMP server. I cannot debug anything because I'm getting an HTTP 500 error when I run the script. However, I know PEAR is installed.
Code:
require_once "Mail.php";
$from = "Email<[email protected]>";
$to = "[email protected]";
$subject = "ERROR REPORT";
$body = "test message";
$host = "ssl://smtp.gmail.com";
$port = "465";
$username = "[email protected]";
$password = "pass1";
$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'port' => $port,
'auth' => true,
'username' => $username,
'password' => $password));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
echo("Error message sent!");
}
It appears to be bugging out at the send() command above. Any suggestions on how to better debug this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
查看 Web 服务器的错误日志,即
/var/log/apache2/error.log
。Have a look at the web server's error log, i.e.
/var/log/apache2/error.log
.尝试以下两行:
将这两行放在脚本的前面会绕过 php.ini 设置,否则会隐藏错误。希望有帮助!
另外,如果可以的话,将它们放在被调用的 PHP 文件中,然后包含使用邮件函数的文件。这样,您就可以避免上面的代码由于语法错误而无法工作。
Try the following two lines:
Placing those two early in the script bypasses the php.ini settings that would hide the errors otherwise. Hope that helps!
Also, if you can, place them in the PHP file that gets called and then include the file that uses the mail functions. That way, you avoid the code above not working due to a syntax error.