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: my_address@gmail.com
Received: by with SMTP id o6csp468220wbq;
        Thu, 16 Aug 2012 00:21:15 -0700 (PDT)
Received: by 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. [])
        by mx.google.com with ESMTP id s18si1547632igi.61.2012.;
        Thu, 16 Aug 2012 00:21:15 -0700 (PDT)
Received-SPF: pass (google.com: domain of bounce+95719fab75@my_smtp_server_domain.com designates as permitted sender) client-ip=;
Authentication-Results: mx.google.com; spf=pass (google.com: domain of bounce+95719fab75@my_smtp_server_domain.com designates as permitted sender) smtp.mail=bounce+95719fab75@my_smtp_server_domain.com; dkim=pass header.i=@mailapproved.com
Received: from ml.my_smtp_server_domain.com.com (ml.my_smtp_server_domain.com.com [])
    by my_smtp_server_domain.com.com (Postfix) with ESMTPA id E3CC68E057
    for <my_address@gmail.com>; 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;
Date: Thu, 16 Aug 2012 15:21:12 +0800
To: Me <my_address@gmail.com>
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: <f2039f590798697bc998c686920020df@ml.my_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;

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?


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.


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 = 'from_email@domain.com';
$mail->Sender = 'sender_email@domain.com';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.