【问题标题】:PHPMailer Lite & GMAIL SMTP: emails not sent to Yahoo Mail, how to debug?PHPMailer Lite & GMAIL SMTP:电子邮件未发送到 Yahoo Mail,如何调试?
【发布时间】: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


【解决方案1】:

由于它与 Gmail 用户一起工作,我的客人会是某些 phpMailer 没有正确发送您的用户名和密码。如果您未通过身份验证,gmail 服务器将不接受中继电子邮件。

一个问题,你为什么不使用自己的电子邮件服务器,这将有助于调试并了解电子邮件未发送的原因。

【讨论】:

  • 没有任何理由,除了 Gmail 是我工作到一半的第一件事。 . .我知道我会将 $mail->host 更改为 localhost 但我不确定其他任何内容。
  • @JIStone:我认为您应该使用自己的服务器。我没有阅读 gmail 限制,但我认为您的使用是边界线,而且在这种情况下,您无法检查任何日志或进行任何深入调试。
  • 好的好的,我去找一些教程
  • @JIStone: 如果你在一些 linux 发行版上,你应该能够很容易地安装 MTA,在 windows IIS 上有一些你可以安装的电子邮件服务器组件。
  • 伙计,我很密集。我只记得在我有一个工作的电子邮件系统之前从事这个项目的那个人,我只需要挖掘他的代码并复制它。
【解决方案2】:

我建议您使用Google App Engine's email service,而不是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()

【讨论】:

    猜你喜欢
    • 2014-10-19
    • 2014-11-30
    • 1970-01-01
    • 1970-01-01
    • 2011-12-19
    • 1970-01-01
    • 2014-05-07
    • 2023-03-28
    • 2017-11-04
    相关资源
    最近更新 更多