0

我编写了一些代码来使用 PHPMailer 从我的 PHP 脚本发送电子邮件。出于某种原因,脚本没有发送消息。


这是我的代码:

<?php
require_once("PHPMailer/class.phpmailer.php");
$mail=new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->Host = "ssl://smtp.gmail.com";
$mail->Port = 465;
$mail->Username = "admin@zbrowntechnology.com";
$mail->Password = "PASSHERE";
$mail->SetFrom = "admin@zbrowntechnology.com";
$mail->AddAddress("zach@zbrowntechnology.com.com");
$mail->Subject = "Confirm Web Lock Registration!";
$mail->Body = "Please confirm your Web Lock Registration by clicking here!";
$mail->WordWrap = 50;

if(!$mail->Send())
{
   echo 'Message was not sent.';
   echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
  echo "Message Sent!";
}
?>

这是回响的错误:

SMTP Error: Could not connect to SMTP host. Message was not sent.Mailer error: SMTP Error: Could not connect to SMTP host.
4

5 回答 5

3

您的错误消息可能是由服务器上的防火墙设置引起的。此错误消息通常是由防火墙阻止端口上的传出连接引起的。

您还应该确保启用了 openssl 扩展。

您修复的原始答案:

您发送到 zach@zbrowntechnology.com.com,这不是您想要的地址。

您需要删除第二个 .com 并将其更改为 zach@zbrowntechnology.com

于 2010-10-21T17:23:25.487 回答
2

我也在使用 PHPMailer,刚刚尝试了您的设置,并得到了同样的错误。这是我的设置,对我有用(我用 ->> 你没有的东西来展示,或者对我来说不同)

$mail->PHPMailer = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true;
->> $mail->SMTPSecure = "ssl";
->> $mail->Host = "smtp.gmail.com"; //not ssl://smtp.gmail.com
$mail->Port = 465; etc...

其他一切都是一样的,除了我不使用自动换行,但我检查了,它没有导致问题。

于 2010-10-21T19:06:09.297 回答
1

您需要指定gmail用户名和密码,因为这是您在 smtp 设置中使用的:

$mail->Username = "email_address@gmail.com";
$mail->Password = "yourgmailpassword";
于 2010-10-21T17:20:39.570 回答
1

作为一般提示,请尝试打开调试:

$mail->SMTPDebug  = 2; // enables SMTP debug information (for testing)
                       // 1 = errors and messages
                       // 2 = messages only

从 SO:调试 PHP Mail() 和/或 PHPMailer

于 2010-10-21T17:24:20.670 回答
0

正如你可能还想尝试使用 Zend_Mail 的一点建议,你可以愉快地使用它,而不必走整个 MVC 路线,它提供了非常丰富的信息

于 2010-10-21T17:39:23.427 回答