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

2022-01-14 00:00:00 email xampp osx-mountain-lion php

我昨天刚刚将 OS X 更新到 Mountain Lion,但是 php 函数 mail() 不再起作用了.

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

更新前,PHP mail() 函数运行良好,Apple 邮件运行良好.更新后,Apple 邮件可以正常工作,但是 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.

网络服务器:XAMPP 1.7.3

Webserver: XAMPP 1.7.3

我用这段代码来测试mail()函数:

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

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

显示:不发送

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

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

提前致谢.

推荐答案

终于找到了解决方案.查看error_log(/Applications/XAMPP/xamppfiles/logs/error_log)后,出现错误:sendmail:致命:chdir/Library/Server/Mail/Data/spool:没有这样的文件或目录

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

在终端执行以下操作:

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

然后 php mail() 工作!

Then the php mail() works!

参考:https://apple.stackexchange.com/questions/54051/sendmail-os-x-mountain-lion 上的错误

相关文章