我写了一些代码,使用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.
答案 0 :(得分:3)
您的错误消息可能是由服务器上的防火墙设置引起的。此错误消息通常是由防火墙阻止端口上的传出连接引起的。
您还应确保已启用openssl扩展程序。
您修正的原始答案:
您要发送到zach@zbrowntechnology.com.com,这不是您想要的地址。
您需要删除第二个.com并将其更改为zach@zbrowntechnology.com
答案 1 :(得分:2)
我也在使用PHPMailer,只是尝试了你的设置,并得到了同样的错误。 以下是我为她设置的设置(我用 - &gt;&gt;显示你没有的东西,或者对我不同)
$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...
其他一切都是一样的,除了我不使用自动换行,但我检查过,这不会导致问题。
答案 2 :(得分:1)
您需要指定 gmail 用户名和密码,因为这是您在smtp设置中使用的内容:
$mail->Username = "email_address@gmail.com";
$mail->Password = "yourgmailpassword";
答案 3 :(得分:1)
作为一般提示,请尝试启用调试:
$mail->SMTPDebug = 2; // enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only
答案 4 :(得分:0)
正如一些建议你可能也想尝试使用Zend_Mail,你可以愉快地使用它,而不必去整个MVC路线,它是非常有用的