mail()函数用于处理未到达的电子邮件


mail() function aparently working emails not arriving

嗨,首先我测试邮件功能,允许显示错误并使用它进行测试。

<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');

$email = "demo@gmail.com";
$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: PHP caches file status so we need to clear
* that cache so we can get the current file size
*/
clearstatcache();
$finalsize = filesize($eLog);
//Check if the error log was just updated
if ($originalsize != $finalsize) {
print "Problem sending mail. (size was $originalsize, now $finalsize) See $eLog
";
} else {
print "Mail sent to $email";
}
?>

这是在告诉我这正在工作并发送电子邮件。。

问题是应该使用此代码发送的邮件没有到达demo@gmail.com账户(我换成真正的电子邮件)

为什么?在php.ini中似乎也不错,但也许我没有找到合适的参数。

我不在乎那次否决,好吧,我终于明白了发生了什么,这应该会帮助另一个"非神程序员",一个像我一样的凡人。

如果您在linux服务器上,那么mail()函数似乎被发送到sendmail函数,要启用它,您必须安装postfix。

这很容易。。并解决我所有的问题。

http://whiletruecode.com/post/setting-up-phps-mail-function-on-a-linode-server