-1

My mails using php mail() are going to the junk mail folder - why?

<?php
    ob_start();
    session_start();

    //define the receiver of the email
    $from='mrashidap@gmail.com';
    $to = 'mrashidap@gmail.com';
    //define the subject of the email
    $subject = 'inform me please, when u receive this mail'; 
    //create a boundary string. It must be unique 
    //so we use the MD5 algorithm to generate a random hash
    $random_hash = md5(date('r', time())); 
    //define the headers we want passed. Note that they are separated with \r\n
    #Now We Can Use HTML Tags

    $headers = "From: " . strip_tags($from). "\r\n";
    $headers .= "Organization: appstribes\r\n";
    $headers .= "MIME-Version: 1.0\r\n";
    $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
    $headers .= "Reply-To: ".($from) . "\r\n";
    $headers .= "Return-Path: ".($from) . "\r\n";
    $headers .= "X-Priority:3 \r\n";
    $headers .= "X-Mailer: PHP". phpversion() ."\r\n";
     $headers .= "X-MSMail-Priority: high\r\n";

    $msg = '<html><body>';
    $msg .= '<p>Dear Sir/Madam</p><br/>';
    $msg .= '<p><strong>GOOD DAY..!!!</strong></p>';
    $msg .= '<p>Thank you for contacting Keita Customer Service. We regret any inconvenience you have experienced. Your request has been received, and a ticket has been created for you with,</p>';
    $msg .= '<p><strong>Reference ID : khd004</strong></p>';
    $msg .= '<p>Our team is looking into your request and you can expect next to be contacted with either an answer to your question(s) or a solution to the issue(s) raised. Our expected time-frames to respond will vary according to the severity or complexity of the matter being addressed and volume of contacts reaching us. However we assure you that we are working to get back to you as fast as possible and to properly address your questions and concern.</p>';
    $msg .= '<p>Regards,</p>';

    $msg .= '<p>Keita IT Team</p><br/>';

    $msg .= '</body></html>';
    $message=$msg;

    //send the email
    $mail_sent = @mail( $to, $subject, $message, $headers );
    //if the message is sent successfully print "Mail sent". Otherwise print "Mail failed" 
    echo $mail_sent ? "Mail sent" : "Mail failed";
    ?>

Most of the mails are going to junk. However mail sending to gmail are getting in inbox itself.

halfer
  • 19,824
  • 17
  • 99
  • 186
Rashid
  • 127
  • 2
  • 3
  • 12
  • 3
    Read this topic [PHP mail form doesn't complete sending e-mail](http://stackoverflow.com/questions/24644436/php-mail-form-doesnt-complete-sending-e-mail) – Qirel Mar 16 '16 at 14:58
  • Don't you think the receiving mail server will score the email and decide whether it goes to junk or not? – frz3993 Mar 16 '16 at 15:00
  • but all mails are not going to junk.. i am asking that how can i send a mail from php as not junk to all mail servers.. thank you – Rashid Mar 16 '16 at 15:02
  • In the link provided by Qirel you will find how to ensure that emails won't be marked as spam. Follow the advices in the answer and then edit your question with the results. – A.L Mar 16 '16 at 15:03
  • If you use gmail to send the mail, that will take DKIM, SPF out of the question. Most probably some keywords in the email can cause it. Keywords that might indicate that the email is created automatically or for advertisement purpose. Might be caused by the number of recipients too. The rule to filter spam can differ from server to server. – frz3993 Mar 16 '16 at 15:13
  • I am using my server and using a mail ID with my domain.. When i am sending to gmail, its going to inbox as normal. But when i am sending mails to other servers, like exchange server, its going to junk. I am using penta10 server for sending mail.. But... – Rashid Mar 16 '16 at 16:22

1 Answers1

0
  1. Your script claims this email is sent from gmail, which is not true
  2. Not clear whether your server signs emails with DKIM or not, does it have SPF or not
  3. Server may be graylisted
  4. Google may not designate your domain as a permitted sender

Any of these reasons may lead to considering your emails as spam.

sotona
  • 1,731
  • 2
  • 24
  • 34