[英]PHPMailer Lite & GMAIL SMTP: emails not sent to Yahoo Mail, how to debug?
我正在尝试使用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();
更新:发现了问题:我们的服务器已被Yahoo列入黑名单(不是我的错),因此浪费了一天半的时间。
由于它与Gmail用户一起使用,因此我的来宾是一些phpMailer无法正确发送您的用户名和密码。 如果您未通过身份验证,gmail服务器将不接受中继电子邮件。
一个问题,为什么不使用自己的电子邮件服务器,这将有助于调试并了解为什么不发送电子邮件。
我建议您使用Google App Engine的电子邮件服务代替gmail。 它为您完成了所有繁重的工作。 同样是因为gmail有一个发送限制,而应用引擎的发送限制要高得多。 它还有大量的免费配额(每天1000个收件人)。
这是从当前登录用户发送消息的示例,如果未登录,则使用login_required注释将用户重定向到登录页面:
from google.appengine.api import mail
from google.appengine.api import users
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import login_required
class InviteFriendHandler(webapp.RequestHandler):
@login_required
def post(self):
to_addr = self.request.get("friend_email")
if not mail.is_email_valid(to_addr):
# Return an error message...
pass
message = mail.EmailMessage()
message.sender = users.get_current_user().email()
message.to = to_addr
message.body = """
I've invited you to Example.com!
To accept this invitation, click the following link,
or copy and paste the URL into your browser's address
bar:
%s
""" % generate_invite_link(to_addr)
message.send()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.