安装postfix解决php发送邮件

最开始是发现apache错误日志,提示找不到sendmail。
随安装sendmail。
而后轮到mail.err报发送邮件失败。

搜索得知,sendmail年老失修,建议用postfix替代之。
安装很简单

$sudo apt-get install postfix

php代码测试

n";
$headers .= "Reply-To: test <${sender}>n";
$headers .= "MIME-Version: 1.0n";
$headers .= "Content-Type: multipart/alternative; boundary=\"$mime_boundary\"n";
echo mail($to, $subject, $message, $headers);
?>

检查日志,还是发送失败,提示找不到gmail邮件服务器。
修改vim /etc/postfix/main.cf
inet_interfaces = all
改为
inet_interfaces = localhost
重启postfix

$sudo service postfix restart

再次用上面的php脚本测试,发送成功。gmail邮箱收到邮件,不过在垃圾邮箱里面:(

标签: ubuntu, php, postfix

添加新评论