PHP PEAR 邮件错误

发布于 2024-11-09 06:17:58 字数 1259 浏览 0 评论 0原文

我在尝试发送电子邮件时收到以下代码错误。它可以在我的本地计算机上运行,​​但当我将其放在我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

允世 2024-11-16 06:18:06

查看 Web 服务器的错误日志,即 /var/log/apache2/error.log

Have a look at the web server's error log, i.e. /var/log/apache2/error.log.

记忆之渊 2024-11-16 06:18:04

尝试以下两行:

ini_set('display_errors','on');
error_reporting(E_ALL);

将这两行放在脚本的前面会绕过 php.ini 设置,否则会隐藏错误。希望有帮助!

另外,如果可以的话,将它们放在被调用的 PHP 文件中,然后包含使用邮件函数的文件。这样,您就可以避免上面的代码由于语法错误而无法工作。

Try the following two lines:

ini_set('display_errors','on');
error_reporting(E_ALL);

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文