PHPMailer sending email into SPAM on GMAIL

Posted on 2012-09-16
Last Modified: 2012-09-17

I am using PHPMailer 5 for sending emails, but for some reason the Gmail Addresses show up in the Gmail SPAM folder.

Here's The code:
//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded

$mail             = new PHPMailer();

$body             = "<html><head></head><body>" . urldecode($_GET["body"]) . "</body></html>";

$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPDebug  = 2;                     // enables SMTP debug information (for testing)
                                           // 1 = errors and messages
                                           // 2 = messages only
$mail->SMTPAuth   = true;                  // enable SMTP authentication
//$mail->SMTPSecure = "tls";                 // sets the prefix to the servier
$mail->Host       = ""; // sets the SMTP server
$mail->Port       = 25;                    // set the SMTP port for the GMAIL server
$mail->Username   = "<classified>"; // SMTP account username
$mail->Password   = "<classified>";        // SMTP account password

$mail->SetFrom("", "Hospital and Physician Locator Service");

$mail->AddReplyTo("", "Hospital and Physician Locator Service");

$mail->Subject    = $_GET["sbjt"];

$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test


$address = $_GET["email"];
$toname = $_GET["ename"];
$mail->AddAddress($address, "John Doe");

//$mail->AddAttachment("images/phpmailer.gif");      // attachment
//$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment

if(!$mail->Send()) {
  echo "Mailer Error: " . $mail->ErrorInfo;
} else {
  echo "Message sent!";


Open in new window

Here's the result of the SMTP send:
SMTP -> FROM SERVER:220 ESMTP MailEnable Service, Version: -5.11- ready at 09/16/12 22:40:45

<br />SMTP -> FROM SERVER: [], this server offers 5 extensions
250-SIZE 26214400

<br />SMTP -> FROM SERVER:250 Requested mail action okay, completed

<br />SMTP -> FROM SERVER:250 Requested mail action okay, completed

<br />SMTP -> FROM SERVER:354 Start mail input; end with <CRLF>.<CRLF>

<br />SMTP -> FROM SERVER:250 Requested mail action okay, completed

<br />Message sent!    

Open in new window

how can I rig this so it will stay out of SPAM folders?
Question by:Evan Cutler
    LVL 6

    Expert Comment

    The headers for the email at Gmail should have something regarding why the email was sent to the spam folder, like a spam score and details on how the score was achieved.
    LVL 9

    Author Comment

    by:Evan Cutler
    Here's the headers from the latest email:

    Received: by with SMTP id bb10csp161862oab;
            Sun, 16 Sep 2012 20:51:42 -0700 (PDT)
    Received: by with SMTP id n21mr6619143qct.82.1347853901999;
            Sun, 16 Sep 2012 20:51:41 -0700 (PDT)
    Return-Path: <>
    Received: from ( [])
            by with ESMTP id m12si4294824qct.184.2012.;
            Sun, 16 Sep 2012 20:51:41 -0700 (PDT)
    Received-SPF: neutral ( is neither permitted nor denied by best guess record for domain of client-ip=;
    Authentication-Results:; spf=neutral ( is neither permitted nor denied by best guess record for domain of
    Received: from ([]) by with MailEnable ESMTP; Sun, 16 Sep 2012 22:51:40 -0500
    Date: Mon, 17 Sep 2012 03:51:40 +0000
    To: John Doe <>
    From: Hospital and Physician Locator Service <>
    Reply-to: Hospital and Physician Locator Service <>
    Message-ID: <>
    X-Priority: 3
    X-Mailer: PHPMailer 5.1 (
    MIME-Version: 1.0
    Content-Type: multipart/alternative;
    X-ME-Bayesian: 0.016491
    Content-Type: text/plain; charset = "iso-8859-1"
    Content-Transfer-Encoding: 8bit
    To view the message, please use an HTML compatible email viewer!
    Content-Type: text/html; charset = "iso-8859-1"
    Content-Transfer-Encoding: 8bit
    <Body was truncated for EE>

    Open in new window

    LVL 34

    Accepted Solution

    I wrote an article on this topic:

    Chances are that you need to implement SPF and send it from a fixed IP address with reverse IP set up.
    LVL 34

    Assisted Solution

    Also make sure you don't use all-caps in your subject line, and make sure you don't misspell anything (e.g. HSPTL should be Hospital) . Those are two typical flags that indicate a spammy message.
    LVL 34

    Assisted Solution

    By the way, just to further push the need for SPF - look at header line 11. A neutral SPF means that you don't have it set up at all. SPF is easy to implement and completely free to do. It's just a matter of adding a TXT record in your DNS for
    LVL 9

    Author Closing Comment

    by:Evan Cutler
    Thanks very much.
    it appears as the most interesting fact is that I am using a Plesk email on a shared server.
    Once I figure out how to get a stable email, I wont' be able to solve this.

    Thanks much, and I'll grant you points on your blog entry.

    Most appreciative.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    These days socially coordinated efforts have turned into a critical requirement for enterprises.
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now