PHPMailer email goes to spam, Outlook email doesn't

12,220

Solution 1

I was having the same problem using PHPMailer, and here's what fixed the problem for me: set the Sender (this is different and distinct from the "From") to a valid email account for the domain you are sending the email from. This causes PHPMailer to properly set the "envelope-from" information so that the email passes SPF and Sender-ID validation. Without doing this, the "envelope-from" is an OS level user id and server combination which will not be verifiable. I hope this helps.

Example Code:

$mail = new PHPMailer;

$mail->From = '[email protected]';
$mail->Sender = '[email protected]';
...

Solution 2

The headers sent by Outlook and PHPMailer, or any other mailer, are different. Many spam filters will automatically increase a message's spam score when such headers are detected. This is presumably because they are so prevalent in spam.

As a first step remove any headers that identify the sending system as being PHPMailer. If that doesn't help then look at the message itself and try to modify it so that it looks less like spam, as your message may be riding the edge.

Share:
12,220

Related videos on Youtube

Cameron Ball
Author by

Cameron Ball

I like maths, physics and computer science. Also sequential movement puzzles.

Updated on September 18, 2022

Comments

  • Cameron Ball
    Cameron Ball almost 2 years

    I'm sending out emails using PHPMailer through an SMTP server that I control, and I have DKIM and SPF set up and working properly, however, when I send a test email to my gmail account it goes to the spam folder immediately and claims that my email is similar to messages detected by their spam filters.

    However, if I then use Outlook to send the exact same message through the same SMTP server, it doesn't get filtered as spam.

    These are the headers from an email that went to spam

    Delivered-To: [email protected]
    Received: by 10.227.117.6 with SMTP id o6csp468220wbq;
            Thu, 16 Aug 2012 00:21:15 -0700 (PDT)
    Received: by 10.43.117.129 with SMTP id fm1mr196323icc.1.1345101675202;
            Thu, 16 Aug 2012 00:21:15 -0700 (PDT)
    Return-Path: <bounce+95719fab75@my_smtp_server_domain.com>
    Received: from mailapproved.com (mailapproved.com. [199.195.193.140])
            by mx.google.com with ESMTP id s18si1547632igi.61.2012.08.16.00.21.14;
            Thu, 16 Aug 2012 00:21:15 -0700 (PDT)
    Received-SPF: pass (google.com: domain of bounce+95719fab75@my_smtp_server_domain.com designates 199.195.193.140 as permitted sender) client-ip=199.195.193.140;
    Authentication-Results: mx.google.com; spf=pass (google.com: domain of bounce+95719fab75@my_smtp_server_domain.com designates 199.195.193.140 as permitted sender) smtp.mail=bounce+95719fab75@my_smtp_server_domain.com; dkim=pass [email protected]
    Received: from ml.my_smtp_server_domain.com.com (ml.my_smtp_server_domain.com.com [199.195.193.133])
        by my_smtp_server_domain.com.com (Postfix) with ESMTPA id E3CC68E057
        for <[email protected]>; Thu, 16 Aug 2012 07:21:12 +0000 (UTC)
    DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=my_smtp_server_domain.com;
        s=server1; t=1345101672;
        bh=TsyHxri8hUJjEnMBm8JUJzfLs5a3ea9aRZQ15toMNyQ=;
        h=Date:To:From:Reply-to:Subject:List-Unsubscribe;
        b=hOUSOx/fN8ZwTlEp4KBAKSGRZHgH6kSj0xUeLlq8J2JGBEE2x6c2b5sh/nFwqx45T
         kuorzu3TsLDDMHCBLmSNLfrYWqyCzkT4Iwh1NJlCL5zm4GwYDXVrVsd+6AjJNfzPN+
         W5idEJ62+MCgsMqgCd6gmpACMcqntgwgp+WcLKFc=
    Date: Thu, 16 Aug 2012 15:21:12 +0800
    To: Me <[email protected]>
    From: Someone <no-reply@my_smtp_server_domain.com>
    Reply-to: No Reply <no-reply@my_smtp_server_domain.com>
    Subject: Welcome to Blah
    Message-ID: <[email protected]_smtp_server_domain.com>
    List-Unsubscribe: <mailto:unsubscribe@my_smtp_server_domain.com?subject=Unsubscribe>, <http://ml.my_smtp_server_domain.com.com/unsubscribe/e783daa664>
    MIME-Version: 1.0
    Content-Type: multipart/alternative;
        boundary="b1_f2039f590798697bc998c686920020df"
    

    There are two servers here: my_smtp_server_domain.com which is the SMTP server, and ml.my_smtp_server_domain.com which is a mailing app (for legit newsletters for people who have double OP'd in).

    The message itself is just a simple confirmation email for a mailing list.

    I don't understand how it can work when I use Outlook but fail with PHPmailer, what's different?

    • Michael Hampton
      Michael Hampton almost 12 years
      PHPMailer is different.