Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

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.

Webserver: XAMPP 1.7.3

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

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

It shows: not send

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

Thanks in advance.

like image 963
Globalfish Avatar asked Jul 27 '12 22:07

Globalfish


People also ask

Does PHP mail function work?

Unless you mean delivering mail to the webmaster, it doesn't make sense for the webmaster to configure things. You're asking the wrong question - there is nothing wrong with the mail() function in PHP - it's not unreliable. The problem is contents and distribution of your mails.

What mail server does PHP mail use?

Php uses by default, the local mail-server.

Does PHP mail use postfix?

Making PHP mail() work with Sendmail/Postfix Sending mail from your server can be done via an internal SMTP or an external one. For the latter, you can use PHPMailer. But sometimes, our own server on localhost is preferred. Do do this, you need to have either Sendmail or Postfix.


1 Answers

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

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!

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

like image 194
Globalfish Avatar answered Oct 16 '22 00:10

Globalfish