1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

PHP mail ending up in SPAM folder

Discussion in 'PHP' started by karl_murphy, Dec 15, 2016.

  1. #1
    Hi,

    I've got a simple email script which does successfully send an email to the recipient, however the email always ends up in their SPAM folder. The code is as follows:

    <?php
    
    $to = $_POST[remail];
    $subject = "Thank you for registering";
    
    $message = "
        <html>
        <head>
        <title>Thank you for registering</title>
        </head>
        <body>
        <p>To activate your account please click the link below.</p>
        LINK
        </body>
        </html>
        ";
    
        $headers = "MIME-Version: 1.0" . "\r\n";
        $headers .= "Content-type:text/html; charset=iso 8859-1" . "\r\n";
    
        $headers .= 'From: <donotreply@*************>' . "\r\n";
    
    mail($to,$subject,$message,$headers);
    
    ?>
    PHP:
    Any help with this would be greatly appreciated.

    Thanks.
     
    Last edited by a moderator: Dec 18, 2016
    karl_murphy, Dec 15, 2016 IP
  2. hdewantara

    hdewantara Well-Known Member

    Messages:
    533
    Likes Received:
    47
    Best Answers:
    25
    Trophy Points:
    155
    #2
    Try using "from" and "reply-to" addresses which come from same domain of where your mail() script resides.
    So unless you're the owner of Google, it can't be
    Perhaps?
     
    hdewantara, Dec 15, 2016 IP
  3. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,622
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #3
    Also, make sure your server is set up with proper records to allow for email-sending. You can read up here, for a quite in-depth explanation why you might not want to run your own mail-server, and how to do it if you still do want to do that.
     
    PoPSiCLe, Dec 18, 2016 IP
  4. Einheijar

    Einheijar Well-Known Member

    Messages:
    539
    Likes Received:
    13
    Best Answers:
    3
    Trophy Points:
    165
    #4
    Sending directly via MTA is considered a huge faux pas nowadays, try setup a proper SMTP server with DKIM / SPF
     
    Einheijar, Dec 18, 2016 IP
  5. MayurGondaliya

    MayurGondaliya Well-Known Member

    Messages:
    1,233
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    170
    #5
    PHP mail function defaults to the shared IP of your server (for most hosts) and does not add necessary headers such as DKIM.

    The best way to improve a delivery is to setup the email/SMTP account (with your cpanel/plesk, etc panel and/or third party smtp provider). Set up proper SPF/DKIM DNS records for that domain in question.

    I suggest to use phpmailer or swiftmailer libraries for SMTP authenticated emails.

    Keep in mind that, in-boxing the email is mainly dependent on IP address reputation, IP usage history, domain reputation, your email content and so on.
     
    MayurGondaliya, Jan 30, 2017 IP
  6. w4l1dz

    w4l1dz Peon

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #6
    hi , please can you check your server ip if its backlisted or not !
    -please try to use the from email a real working email
    try to use this header and change what neseccary

    $header = "MIME-Version: 1.0\n";
    $header .= "Content-type: text/html; charset=iso-8859-1\n";
    $header .= "From: "*****@*****.*** " <" . $de . ">\n";
    $header .= "Reply-To: " *****@*****.*** "\n";
    $header .= "X-Priority: 3\n";
    $header .= "X-MSMail-Priority: Normal\n";
    $header .= "X-Mailer: ".$_SERVER["HTTP_HOST"];
     
    w4l1dz, Feb 28, 2017 IP