我已经看到成千上万个关于这个主题的类似问题。并且肯定知道SO中的“标记为重复问题”的事情。
然而,仍然不清楚如何或做什么简单地说要从 PHP mail() 函数中获得 yahoo Inbox 电子邮件。
在 Yahoo 站点中,他们提供了一个示例脚本来发送邮件,例如
链接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
使用这种在雅虎自己的合法网站中发现的基本方法失败了。
第二个建议是(对于 PERL),但可以通过一些编辑转换为 PHP:
#!/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>";
链接:http ://help.yahoo.com/l/us/yahoo/smallbusiness/webhosting/php/php-17.html
经过几次编辑使其成为 PHPish 后,它看起来像:
<?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!";
}
?>
user_name2@gmail.com
GMAIL 根据需要发送电子邮件,但不知user_name@yahoo.com
何故没有去任何地方。
那么,我们应该怎么做呢?...如果雅虎自己的样本不起作用,那么:
a) PHP mail() 函数是否被弃用?...如果是,还有什么替代方案?
b) 如果该功能仍然有效,我们如何提供YAHOO Inbox 友好的PHP 代码?
c) PHP mail() 函数的最佳实践是什么?
编辑:
附加测试。
刚刚以这种格式对其进行了测试,建议通过PHP mail() 函数不发送电子邮件:
$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";
雅虎仍然没有收件箱。
编辑2
我去了这个链接:http ://www.forensicswiki.org/wiki/Evolution_Header_Format
YAHOO说标题应该是这样的:
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
收到,再次,YAHOO
被拒绝...我没有错误Logs