-2

Here is the simple using of php mail() function codes :

<?php
$from    = "From email goes here";
$to      = "To email goes here";

ini_set("display_errors", "On");
ini_set("sendmail_from", $from);
ini_set("SMTP", "localhost");
ini_set("smtp_port", "25");

$subject = "Hello, This is subject";

$message = "<p style='color: green;font-weight: bold;'>Hello World, This is Body</p>";

$headers  = 'MIME-Version: 1.0' . "\r\n";
//$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'Content-Type: text/html; Charset=UTF-8' . "\r\n";

$headers .= 'From: Birthday Reminder <' . $from . '>' . "\r\n";
$headers .= 'To: Mary <' . $to . '>' . "\r\n";
$headers .= 'Reply-To: Birthday Reminder <' . $from . '>' . "\r\n";
$headers .= 'X-Mailer: PHP/' . phpversion();

if(mail($to, $subject, $message,$headers))
{
  echo("<p style='color: blue;font-weight: bold;'>Email Sent :D</p>");
} 
else 
{
  echo("<p style='color: red;font-weight: bold;'>Email Message delivery failed...</p>");
}
?>

Why emails were sent using these codes always go to the spam folder?
Is the order of headers ok?
Which extra headers should i use for prevent spam?

Edit :
I know there are some threads in stack about that.
But i am looking for an updated answers.
So it's not duplicate.

SilverLight
  • 19,668
  • 65
  • 192
  • 300
  • Most likely because **anyone** can send out a "regular" email like that, you need to setup your server to "confirm" who you are / add some credebility, check out SPF and DKIM – Epodax Dec 22 '15 at 13:51

1 Answers1

1

This not only about your script, you may check the reputation of your IP, you shall also set SPF record and DKIM key for help

https://mxtoolbox.com/

This online tool will help you to setup properly your mail server

You may check the senderscore of your IP, since it can affect badly the delivery of your mails

https://www.senderscore.org

Anyone_ph
  • 616
  • 6
  • 15