首先我测试邮件功能,允许显示错误并使用它来测试。
<?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中也似乎没问题,但也许我没有找到合适的参数。
答案 0 :(得分:1)
我不关心那个downvote,好吧我终于知道这是什么应该帮助另一个“不上帝程序员”一个凡人,像我一样..
如果你在linux服务器上,似乎mail()函数被发送到sendmail函数,要启用此功能你必须安装postfix。
这很容易..并解决我的所有问题。
http://whiletruecode.com/post/setting-up-phps-mail-function-on-a-linode-server