在许多阻止的电子邮件中使用PHPMailer结果

I am using PHPmailer; though probably a version from 2012 - I haven't updated it for a while.

I am sending mail like this:

        $mail = new PHPMailer();
        $mail -> IsSMTP();
        $mail -> Host = "localhost";
        $mail -> Port = 587;
        $mail -> SMTPAuth = true;
        $mail -> Username = EMAIL_USER;
        $mail -> Password = EMAIL_PASS;
        $mail -> From = EMAIL_USER;
        $mail -> FromName = "My Company";
        $mail -> AddAddress($email);  
        $mail -> AddReplyTo('<Same as "FROM">', 'User Name');
        $mail -> IsHTML(true);
        $mail -> Subject = 'This is my subject';
        $mail -> Body = $body;
        $result = $mail -> Send();

I have had many emails bounce back using the above code. I even removed the body variable and just hard coded "test" in there -- so I don't think my body is the cause.

I am wondering if there are other headers that I am not using that would help or does PHPMailer take care of this behind the scene?

EDIT: I am really asking if I a missing any important header information?

Well I solved the issue; the code above was not the problem and works great.

In my subject, I used a phrase regarding "verify your account information" and that got it blocked on a few ISP's.

So the lesson is, your subject matters. I was looking at my php code and my body content before I realized this.

Some other things to note too when dealing with rejected mail:

  • The server you are sending mail from matters a lot. Many, like AWS, are blacklisted by default, and you need to request special permission to be able to send mail. Use a blacklist-check if you're not sure.
  • Always always create an appropriate SPF txt record for your domain (in DNS). This ensures that the sending server is a verified sender for your domain.
  • If you're having troubles sending mail, check the server logs to see why. Many providers (Outlook.com for example) will provide good feedback in the form of an RFC number or even a link to follow for more information.
  • When all else fails, use a mail gateway API like SendGrid, Mandrill, or Amazon SNS.