【发布时间】:2010-12-15 02:32:04
【问题描述】:
我正在尝试使用 phpMailer 和 GMail SMTP 发送电子邮件。它可以很好地向其他 Gmail 帐户发送电子邮件,但向 Yahoo 发送邮件永远不会到达那里。我读过有关使用 ip 地址等进行调试的内容,但我不擅长该领域?
代码如下:
$mail->Mailer='smtp';
try {
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "tls"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 587; // set the SMTP port for the GMAIL server
$mail->Username = "__email__"; // GMAIL username
$mail->Password = "__pass__"; // GMAIL password
$mail->SMTPDebug = 2;
$a = md5(uniqid(rand(), true)); //create a unique validation code
//These are the variables for the email
$mail->AddAddress (trim($_POST['email']),trim($_POST['username'])); // this is the email address collected form the form
$mail->Subject = "Registration"; // Subject
$mail->Body = "Thank you for registering\n your security code is ".$a;
$mail->Send();
echo "check your email to complete registration";
} catch (phpmailerException $e) {
echo $e->errorMessage(); //Pretty error messages from PHPMailer
} catch (Exception $e) {
echo $e->getMessage(); //Boring error messages from anything else!
}
$mail->ClearAddresses();
更新:发现问题:我们的服务器已被雅虎列入黑名单(不是我的错) 所以这是浪费了一天半的时间。
【问题讨论】:
-
您确定邮件没有被垃圾邮件过滤器捕获吗?可以查一下吗?
-
是的,我首先检查了。任何地方都没有邮件。
标签: php debugging smtp gmail phpmailer