33

我昨天刚刚将 OS X 更新为 Mountain Lion,但 php 功能mail()不再起作用。

更新前,PHPmail()功能正常,Apple 邮件正常。更新后,Apple 邮件可以正常工作,但 PHPmail()功能无法正常工作。

网络服务器:XAMPP 1.7.3

我使用此代码来测试mail()功能:

if (mail($to, $object, $content, "From: ". $from)) 
{ 
    echo 'send '; 
} 
else 
{ 
    echo "not send"; 
}

表明:not send

我有什么需要改变的吗?比如 thephp.ini还是别的什么?

提前致谢。

4

2 回答 2

79

最后我找到了解决方案。查看error_log(/Applications/XAMPP/xamppfiles/logs/error_log)后,有错误: sendmail: fatal: chdir /Library/Server/Mail/Data/spool: No such file or directory

在终端执行以下操作:

sudo mkdir -p /Library/Server/Mail/Data/spool
sudo /usr/sbin/postfix set-permissions
sudo /usr/sbin/postfix start

然后 php mail() 工作!

参考: https ://apple.stackexchange.com/questions/54051/sendmail-error-on-os-x-mountain-lion

于 2012-07-29T03:52:58.427 回答
3

如上所述创建假脱机文件夹后,我按照这篇文章OS X 提示中的说明配置了 postfix

我还必须编辑我的 php.ini sendmail 路径以获得一些额外的开关,特别是

sendmail_path=/usr/sbin/sendmail -t -i
于 2012-08-09T07:54:10.837 回答