-1

I am sending a reply mail using PHP to those who send a mail to me.

My problem is when I send an email, it sits in the spam folder. What do I do in order to deliver mail correctly. What should I do?

My code

<?php
    $email_id="welcome@gmail.com";
    $recipient = "@gmail.com"; //Recipient
    $mail_body = $message; //Mail body
    $subject = "Subject ".$Name.""; //Subject
    $header = "From: ". $Name . " <" . $email . ">\r\n"; //Optional headerfields
    $header .='Content-type: text/plain; charset=utf-8'."\r\n";
    mail($recipient, $subject, $mail_body, $header); /mail command :)
?>
Community
  • 1
  • 1
venkatachalam
  • 102,353
  • 31
  • 72
  • 77

3 Answers3

1

Make sure you're populating the From, Reply-To, Sender, Return-Path, and Errors-To headers with the sending e-mail address. There are so many reasons e-mails may be filtered as spam, though - your ISP may be blocked, the contents of the message may contain things that get it flagged, etc.

ceejayoz
  • 176,543
  • 40
  • 303
  • 368
1

The problem is not necessarily in your code. One possibility is that your server's mail transfer agent is misconfigured - I've experienced this issue once. Worth checking.

Joonas Pulakka
  • 36,252
  • 29
  • 106
  • 169
0

The problem is not coming from your code. You may need to configure your service. In order to be accepted by most of the email service providers, you should setup a DomainKey or a Sender Id.

You should also make sure that your IP address is not blacklisted if you are running this code on a dedicated server.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Roch
  • 21,741
  • 29
  • 77
  • 120