I have seen thousands of similar questions asked on this topic. And for sure am aware of the "MARKED AS DUPLICATE QUESTION" thing in SO.
However, it is still not Clear how or what one has to do in simple terms to have yahoo Inbox emails from a PHP mail() function.
In the Yahoo site, they give a sample script to send mails like
Link http://help.yahoo.com/l/us/yahoo/smallbusiness/webhosting/php/php-03.html
$email = "EMAIL TO";
$subject = "Test Message";
$msg = "This is a test message";
//$eLog="/tmp/mailError.log";
//Get the size of the error log
//ensure it exists, create it if it doesn't
//$fh= fopen($eLog, "a+");
//fclose($fh);
//$originalsize = filesize($eLog);
mail($email,$subject,$msg);
//NOTE: I commented out unneeded lines
Using this basic approach found in the Yahoo's own legitimate website fails.
The second suggestion would be (for PERL) but can be converted to PHP with some editing:
#!/usr/bin/perl
print "Content-type: text/html\n\n";
$title='mail test';
$to='MAIL ADDRESS TO SEND TO';
$from= 'EMAIL@YOURDOMAIN.COM';
$subject='Using Sendmail';
open(MAIL, "|/usr/sbin/sendmail -t");
## Mail Header
print MAIL "To: $to\n";
print MAIL "From: $from\n";
print MAIL "Subject: $subject\n\n";
## Mail Body
print MAIL "This is a test message from Yahoo \n";
close(MAIL);
print "<html><head><title>$title<
/title></head>\n<body>\n\n";
## START HTML content
print "<h1>$title</h1>\n";
print "<p>A message has been sent from $from to $to";
## END HTML CONTENT
print "\n\n</body></html>";
Link: http://help.yahoo.com/l/us/yahoo/smallbusiness/webhosting/php/php-17.html
After few edits to make it PHPish it looks like:
<?php
///#!/usr/bin/perl
$title='_01_mail test';
$to='user_name@yahoo.com, user_name2@gmail.com';
$from= 'info@companyname.com';
$subject='_01_Using Sendmail';
## Mail Header
$headers = "To: $to\n";
$headers .= "From: $from\n";
$headers .= "Subject: $subject\n\n";
## Mail Body
$message = "<html><head><title>$title<
/title></head><body>
<h1>$title</h1>
<p>A message has been sent from $from to $to\n\n
</p></body></html>";
if ( mail($to,$subject,$message,$headers) ) {
echo "The email has been sent!";
} else {
echo "The email has failed!";
}
?>
The user_name2@gmail.com
for GMAIL sends the Email as required but user_name@yahoo.com
somehow does not go anywhere.
So, what should we do?... If YAHOO's own samples are not working, then:
a) Is PHP mail() function getting deprecated?... If so, what is the alternative?
b) Should the function still be valid, how do we come up with YAHOO Inbox friendly PHP Codes?
c) What is the best practice for PHP mail() Function?
EDIT:
Additional tests.
Just tested it in this format Suggest by PHP mail() function not sending email:
$subject = "subject";
$message = "message";
$to = "USER_NAME_HERE@yahoo.com";
$type = "plain"; // or HTML
$charset = "utf-8";
$mail = "no-reply@".str_replace("www.", "", $_SERVER["SERVER_NAME"]);
$uniqid = md5(uniqid(time()));
$headers = "From: ".$mail."\n";
$headers .= "Reply-to: ".$mail."\n";
$headers .= "Return-Path: ".$mail."\n";
$headers .= "Message-ID: <".$uniqid."@".$_SERVER["SERVER_NAME"].">\n";
$headers .= "MIME-Version: 1.0"."\n";
$headers .= "Date: ".gmdate("D, d M Y H:i:s", time())."\n";
$headers .= "X-Priority: 3"."\n";
$headers .= "X-MSMail-Priority: Normal"."\n";
$headers .= "Content-Type: multipart/mixed;boundary=\"----------".$uniqid."\""."\n\n";
$headers .= "------------".$uniqid."\n";
$headers .= "Content-type: text/".$type.";charset=".$charset.""."\n";
$headers .= "Content-transfer-encoding: 7bit";
STILL YAHOO DOES NOT INBOX THE MAIL.
EDIT2
I went to this Link: http://www.forensicswiki.org/wiki/Evolution_Header_Format
YAHOO said the header should be like this:
Subject: header test
From: Username <username@sendinghost.com>
To: Username <username@receivinghost.com>
Content-Type: text/plain
Date: Sat, 28 Jul 2007 11:52:35 +0200
Message-Id: <1185616355.19231.0.camel@localhost>
Mime-Version: 1.0
X-Mailer: Evolution 2.10.1
Content-Transfer-Encoding: 7bit
Thested with PHP mail() func.
... GMail
received, again, YAHOO
Rejected... I Get NO Error in the Logs