3

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

Community
  • 1
  • 1
ErickBest
  • 4,586
  • 5
  • 31
  • 43
  • Do you have access to any logs? can you open a session from the server that's sending out the mail? Usually, from a windows box I'd open a telnet to the server I was trying to send to and fake sending a mail. Often times when it fails it's because the server isn't allowing anonymous relaying. – Snowburnt Oct 24 '13 at 02:18
  • *Using this basic approach found in the Yahoo's own legitimate website fails.* This shows how to send an email? Sending an email and not looking like a spammer are two different things. – ta.speot.is Oct 24 '13 at 02:20
  • @Snowburn should there be an issue, how come GMail is receiving the Email as expected?... That's the reason why the question is being asked. WHAT DOES YAHOO WANT?___In simple terms. Have any Idea? – ErickBest Oct 24 '13 at 02:27
  • @ta.spaot.is Then Why wouldnt they put the right approach in the sample and explain that, that is the way.... Why put the Spam version ( **Knowing well that if will Fail** ) as legitimate method if there is an appropriate one....WHAT is the NON_SPAM method??... Any Idea? – ErickBest Oct 24 '13 at 02:29
  • @ErickBest the first page you linked shows you how to validate that your mailLog is working. Take a look there and see what it tells you. The second is the page that you tells you how to send mail. Did you follow the first steps? – Snowburnt Oct 24 '13 at 02:35
  • @Snowburnt Yah, indeed, the steps work perfectly when the email is Gmail. NOT YAHOO... If it is a spam issue then where has YAHOO Documented and Explained the NON_SPAM version of `PHP mail() function` settings?.... any Idea?... Thanx – ErickBest Oct 24 '13 at 03:23
  • again, please check the mail logs and look for why it failed, without that information we're just shooting in the dark. And there's really no reason to be so aggressive, we don't work for yahoo and we're trying to help you. – Snowburnt Oct 24 '13 at 10:47
  • So, you are sending this FROM a yahoo hosted server, right? – Snowburnt Oct 24 '13 at 10:50
  • @Snowburnt, Apologies if I sounded like shouting from a window... You mean YAHOO only accepts `PHP mail() func` if it is hosted locally? or?.. am hosted by exodus.jollyworkshosting.com/... Thnx again – ErickBest Oct 24 '13 at 11:07
  • Humble request... please those wishing to [Close] this question... I seriously Need the Help you may need one day... Please let it be open until we get an answer. Thanks – ErickBest Oct 24 '13 at 11:45
  • 1
    Have you tried frameworks like phpmailer or swiftmailer yet? – sofl Oct 24 '13 at 12:12
  • Sure....Thankx... It's finally done using PHPMailer.. See my answer bellow... Though I still do not know why YAHOO was refusing to receive the mails or should **teacher is schools** no longer teach `PHP mail() function` as a *mailing pivotal point* of PHP and instead teach how to use `PHPMailer...` ? It's confusing.. – ErickBest Oct 24 '13 at 13:17
  • 1
    @ErickBest Here's the deal with SMTP and most mail recipients: SMTP basically acts as a relay for mail programs. When you send mail, you connect to your SMTP relay dump your mail. The SMTP relay looks up where the mail is supposed to go in DNS, connects to the mx server of the domain and dumps the mail again. People started abusing the open nature of this protocol to send spam. To counter this 2 things happened: people required auth so that they could say they knew the people sending mail were legitimate and blacklists were formed blocking known open relays. Thus: required authentication. – Snowburnt Oct 24 '13 at 13:37
  • @Snowburnt Thanks a Kilo... Still how would the authentication be done simply by using the native PHP mail() function? Could you post some codes [Basically] explaining how to authenticate using the indigenous PHP mail() function without third party libraries?...__Respect for you inputs,, thx – ErickBest Oct 24 '13 at 14:17
  • @ErickBest from PHP's documentation I don't think there is a way. PHP integrated PEAR extensions in their stack in version 4 to fill this need. PHP is currently on 5.5.3, so I wouldn't imagine a large host provider would be that far behind in versions. – Snowburnt Oct 24 '13 at 14:22
  • @Snowburnt Amazing...I really appreciate ur inputs. Hope the info in this post got to help someone in the future suffering YAHOOfuncphobia... Thnx a million... – ErickBest Oct 24 '13 at 14:31

2 Answers2

2

I Finally got a laaaaarge smile on my face. Working together with @DaveRandom, He helped me come up with these codes:

NOTE: The code bellow uses PHPMailer

    <?php

            $senderName = 'Erick Best'; //Enter the sender name
            $username = 'erickbestism@yahoo.com'; //Enter your Email
            $password = 'passwordHere';// Enter the Password


            $recipients = array(
                'erickbestism@gmail.com' => 'Erick Best',
                'erickbestism@yahoo.com' => 'Yahoo User',
            );
          ///That's all you need to do

//No need to edit bellow    
            require '../PHPMailerAutoload.php';

            //Create a new PHPMailer instance
            $mail = new PHPMailer();

            // Set up SMTP
            $mail->IsSMTP();
            $mail->SMTPAuth   = true;
            $mail->SMTPSecure = "tls";
            $mail->Host       = "smtp.mail.yahoo.com";
            $mail->Port       = 587; // we changed this from 486
            $mail->Username   = $username;
            $mail->Password   = $password;

            // Build the message
            $mail->Subject = 'PHPMailer mail() test';
            $mail->msgHTML(file_get_contents('contents.html'), dirname(__FILE__));
            $mail->AltBody = 'This is a plain-text message body';
            $mail->addAttachment('images/phpmailer_mini.gif');

            // Set the from/to
            $mail->setFrom($username, $senderName);
            foreach ($recipients as $address => $name) {
                $mail->addAddress($address, $name);
            }

            //send the message, check for errors
            if (!$mail->send()) {
                echo "Mailer Error: " . $mail->ErrorInfo;
            } else {
                echo "Message sent!";
            }

        ?>

And this WORKED like VOODOO!... It sent mails to any provider. Including **YAHOO**

Hope it helps someone!

ErickBest
  • 4,586
  • 5
  • 31
  • 43
0

try this:

<?php 
include("Mail.php"); 

$recipients = "mailto@example.com"; 

$headers["From"]    = "mailfrom@example.com"; 
$headers["To"]      = "mailto@example.com"; 
$headers["Subject"] = "Test message"; 

$body = "TEST MESSAGE!!!"; 

$params["host"] = "example.com"; 
$params["port"] = "25"; 
$params["auth"] = true; 
$params["username"] = "user"; 
$params["password"] = "password"; 

// Create the mail object using the Mail::factory method 
$mail_object =& Mail::factory("smtp", $params); 

$mail_object->send($recipients, $headers, $body); 
?> 

where username and password are for a yahoo account.

Snowburnt
  • 6,523
  • 7
  • 30
  • 43