I am working on a MAMP PRO localhost server. I am very sure emails were being sent some months ago on my localhost from my local applications using php's mail() function. All of a sudden i can't get emails to be sent. I have even moved one of the local websites to a live server on GoDaddy but emails are still not being sent.
The GoDaddy guys swear to that nothing is wrong with their settings and that the issue has to be in my code. Getting back to my localhost MAMP PRO server, i tried all i could to debug, including messing around with the php.ini settings to no avail. I finally reluctantly decided to try an email library, so i went for Swift Mailer. I installed it, wrote the script and now emails are being sent from localhost. I assume it will also work if i put the code on the live server (at GoDaddy).
Here is my mail() code:
$headers = "MIME-Version: 1.0" . "
";
$headers .= "Content-type: text/html; charset=utf-8" . "
";
$headers .= "From: ". "$this->_headerFrom". "
";
$headers .= "Reply-To: "."$email". "
";
$headers .= "Return-Path: "."$email". "
";
$headers .= "X-Mailer: PHP/".phpversion();
$to = "$this->_applicationEmail";
$send = mail($to, $subject, $msg, $headers);
$subject and $msg are all set earlier in the script and they are strings
$send returns true, but no email is sent. I have followed all sorts of
examples here on SO to no avail. It's simple, but mind-boggling all the
same.
I really need to understand why. What is Swift Mailer doing that mail() isn't? I would rather keep my mail() scripts if only i could get them to work. The fact is, i had spent a lot of time writing custom email scripts with several email templates. It would be a heck of a task to rewrite all those mailing scripts to use Swift Mailer. What could make mail() stop working?
MAMP/WAMP need to be set up correctly to send mail.
See http://blog.techwheels.net/send-email-from-localhost-wamp-server-using-sendmail/.
The same for your GoDaddy server you probably need to do something with SMTP to make sure it is set up correctly.
You might need to do a few tests to see if mail is actually getting sent or just get flat out rejected as spam by the server receiving it as it won't have SPF etc,.