更新到 OSX Mountain Lion 后,PHP mail() 不再有效

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11696609/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 01:53:36  来源:igfitidea点击:

PHP mail() no longer works after update to OSX Mountain Lion

phpemailxampposx-mountain-lion

提问by Globalfish

I just updated OS X to Mountain Lion yesterday, but the php function mail()does not work anymore.

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

Before updating, the PHP mail()function worked fine, Apple mail works fine. After updating, Apple mail works fine, but PHP mail()function DOES NOT work.

更新前,PHPmail()功能正常,Apple 邮件正常。更新后,Apple 邮件工作正常,但 PHPmail()功能不起作用。

Webserver: XAMPP 1.7.3

网络服务器:XAMPP 1.7.3

I use this code to test the mail()function:

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

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

It shows: not send

表明: not send

Anything I have to change? such as the php.inior something else?

我有什么需要改变的吗?之类的php.ini还是别的什么?

Thanks in advance.

提前致谢。

回答by Globalfish

Finally I found the solution. After looking at the error_log (/Applications/XAMPP/xamppfiles/logs/error_log), there is an error: sendmail: fatal: chdir /Library/Server/Mail/Data/spool: No such file or directory

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

Do the following at your terminal:

在您的终端执行以下操作:

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

Then the php mail() works!

然后 php mail() 起作用了!

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

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

回答by Ryan

After creating the spool folder as described above, I configured postfix following the directions on this article OS X Hints

如上所述创建 spool 文件夹后,我按照本文OS X Hints上的说明配置了 postfix

I also had to edit my php.ini sendmail path to have some extra switches, specifically

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

sendmail_path=/usr/sbin/sendmail -t -i