PHPMailer-Lite和GMAIL-SMTP:电子邮件未发送到Yahoo Mail,如何调试?
我正在尝试使用phpMailer和GMail SMTP发送电子邮件。向其他Gmail账户发送电子邮件效果很好,但向雅虎发送邮件永远无法到达那里。我读过关于使用ip地址等进行调试的文章,但我在这方面不熟练 代码如下:PHPMailer-Lite和GMAIL-SMTP:电子邮件未发送到Yahoo Mail,如何调试?,php,debugging,smtp,gmail,phpmailer,Php,Debugging,Smtp,Gmail,Phpmailer,我正在尝试使用phpMailer和GMail SMTP发送电子邮件。向其他Gmail账户发送电子邮件效果很好,但向雅虎发送邮件永远无法到达那里。我读过关于使用ip地址等进行调试的文章,但我在这方面不熟练 代码如下: $mail->Mailer='smtp'; try { $mail->SMTPAuth = true; // enable SMTP authentication $mail->SMTPSecure
$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();
更新:发现问题:我们的服务器被雅虎列入黑名单不是我的错
这是浪费了一天半的时间。因为它与Gmail用户一起工作,我的客人可能是一些phpMail用户没有正确发送您的用户名和密码。如果您未经身份验证,gmail服务器将不接受转发电子邮件
有一个问题,为什么不使用自己的电子邮件服务器,这将有助于调试和了解电子邮件为何不发送 我建议您使用gmail而不是gmail。它为你做所有的重担。另外,因为gmail有一个发送限制,而AppEngine的发送限制要高得多。它也有一个慷慨的免费报价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()
你确定邮件不会被垃圾邮件过滤器捕获吗?你能查一下吗?是的我查过的第一件事。任何地方都没有邮件。除了Gmail,没有其他原因。我工作到一半的时候第一件事就是Gmail。我知道我会将$mail->host更改为localhost,但我不确定是否还有其他内容。@JIStone:我认为您应该使用自己的服务器。我没有读过gmail的限制,但我认为你的使用是边界线,而且在这种情况下,你没有办法检查任何日志或进行任何深入的调试。是的,好的,我会找一些tutorials@JIStone:如果您使用的是linux发行版,您应该能够非常轻松地安装MTA,在windows IIS上,你可以安装一些电子邮件服务器组件。伙计,我很笨。我只记得在我有一个可用的电子邮件系统之前,有一个家伙在做这个项目,我只需要挖掘他的代码并复制它。