PHPMailer Lite 和 PHPMailer Lite GMAIL SMTP:电子邮件未发送到雅虎邮箱,如何调试?

发布于 2024-10-08 00:28:00 字数 1447 浏览 4 评论 0原文

我正在尝试使用 phpMailer 和 GMail SMTP 发送电子邮件。向其他 Gmail 帐户发送电子邮件效果很好,但向雅虎发送邮件却永远无法到达那里。我读到有关使用 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();

更新:发现问题:我们的服务器已被雅虎列入黑名单(不是我的错) 这样就浪费了一天半的时间。

I am attempting to send emails using phpMailer and GMail SMTP. It works fine sending emails to other Gmail accounts but sending to Yahoo the mail never gets there. I read about debugging using ip addresses and such, but I am not skilled in that area?

here is the code:

  $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();

update: Found the problem: Our server had been blacklisted by Yahoo (not my fault)
so that's a day-and-a-half wasted.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

戏蝶舞 2024-10-15 00:28:41

我建议您使用 Google App Engine 的电子邮件服务。它会为您完成所有繁重的工作。另外,因为 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()

Instead of gmail I would advise you to use Google App Engine's email service. It does all the heavy lifting for you. Also because gmail has a send limit while app engine's is much higher. It also has a generous free quota(1000 recipients/day.

Here's an example of sending a message from the current signed-in user, using the login_required annotation to redirect the user to the sign-in page if they are not signed in:

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()
只有一腔孤勇 2024-10-15 00:28:39

由于它与 Gmail 用户一起使用,我的客人可能会认为某些 phpMailer 无法正确发送您的用户名和密码。如果您未经过身份验证,gmail 服务器将不会接受中继电子邮件。

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

Since it's working with Gmail users my guest would be that some phpMailer is not sending your username and password properly. The gmail server won't accept to relay email if you are not authenticated.

One question, why don't you use your own email server, it would help to debug and to know why the emails are not sent.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文