Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP mail() on Windows: no errors, the email isn't sent

I'm currently trying to debug an Elgg-based website (I didn't develop it) and I would like to send the emails directly from local development machine (WinXP). I'm running WAMP with Apache 2.2.11 and PHP 5.3.0

After some searching, the simplest solution that I've come across is using fake sendmail to forward it to my GMail/Google apps account via SMTP and let it do the sending. The problem is that I get no errors whatsoever, but the email isn't being sent.

Here's what I did:

  • Copied the sendmail.exe and sendmail.ini to a subfolder in WAMP
  • Configured it via sendmail.ini (the configuration settings are ok)
  • Edited php.ini to add the path to sendmail.exe
    sendmail_path = "C:\Program Files\wamp\bin\sendmail\sendmail.exe -t"
  • Commented out the windows SMTP settings in php.ini
    ; SMTP = localhost
    ; smtp_port = 25
    ; sendmail_from = [email protected]
    ; mail.force_extra_parameters =

The mail.log file shows the following:

mail() on [C:\Program Files\wamp\www\mail.php:9]: To: xxx -- 
Headers: From: xxx  Reply-To: xxx  X-Mailer: PHP/5.3.0

My guess is that the problem is that the default Windows option (to specify the server and not the sendmail utility) is not overriden. In phpinfo() I still get the SMTP -> localhost and smtp_port -> 25 options, even though I commented them.

If anyone managed to get this working, I'd really appreciate some help. In my opinion, using fake sendmail is a lot simpler than installing a mail server on your machine.

Thanks!

P.S. Please don't suggest PHPMailer and the like, because I have to use the mail() function. That's how Elgg works.

like image 202
Alex Ciminian Avatar asked Oct 22 '09 09:10

Alex Ciminian


People also ask

Why is my PHP email not sending?

If you've created a PHP mail form and find it's not sending email, then it's most often due to the FROM address the form is using in its headers. A simple way to confirm if this is the case: Log in to your web server via FTP or SSH.

How do you check PHP mail () is working?

to check if it is sending mail as intended; <? php $email = "[email protected]"; $subject = "Email Test"; $message = "this is a mail testing email function on server"; $sendMail = mail($email, $subject, $message); if($sendMail) { echo "Email Sent Successfully"; } else { echo "Mail Failed"; } ?>

How do I prevent mails sent through PHP mail () from going to spam?

Try PHP Mailer library. Or Send mail through SMTP filter it before sending it. Also Try to give all details like FROM , return-path .

Does PHP mail require SMTP?

PHP mail() does not usually allow you to use the external SMTP server and it does not support SMTP authentication. Here's what you can do with PHP's built-in mail function(): create simple HTML/text messages without attachments and images. send emails via localhost and Xmapp.


1 Answers

I've gotten it to work eventually. The problem was that PHP had a bug in parsing .ini files with spaces in the path (for sendmail). It was fixed in version 5.3.0, but the manual had no info on this.

So, yes, it is possible to use sendmail with PHP on Windows :D.

Thank you all for your time!

like image 112
Alex Ciminian Avatar answered Oct 05 '22 22:10

Alex Ciminian