[英]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.