PHP Email Script (HTML Ready) Update

by Hiroshi on January 22, 2013

in Email Systems

Previously I have posted PHP email scripts here but here is an update that is working for me now. There is one common problem with the email that is sent by using PHP scripts. That is: Email land in junk or spam folder. Here is the solution with HTML ready email. Send PHP email with correct headers info, in HTML format that will not land in receiver’s junk folder or spam folder.

The problem seems to be with the From header. Use correct headers like below and you email will not be marked with spam.

<?php
// $mailto=$txtEmail;
// or
$mailto="receiver_email@emailserver.com";
 
$mailfrom="info@myserver.com";
$mailfrom2="myName <info@myserver.com>";
$subject= "Subject of email";
 
// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From: ".$mailfrom2."\r\n";
$headers .= "Reply-To: ".$mailfrom."\r\n";
$headers .= "Return-Path: ".$mailfrom."\r\n";
$headers .= "Signed-by: sitename.com";
 
// $headers .= 'Cc: mail1@hotmail.com' . "\r\n";
// $headers .= 'Bcc: mail2@hotmail.com' . "\r\n";
 
$mmessage = "
<br /><br />
Hello <strong>Buddy</strong>
<br /><br />
Thanks for joining my website. 
<br /><br />
More text and html code...
<br /><br />
Your brand name
<br />
<a href='https://www.mysite.com'>https://www.mysite.com</a>
";
@mail($mailto, $subject, $mmessage, $headers);
?>

Related Posts

Previous post:

Next post: