views:

470

answers:

4

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.

A: 

Make sure you have SMTP Service running on your local machine and that SMTP Port(25) is opened.

Have a check on the services (Run->services.msc) and look for Send Mail Transfer

If you cannot find SMTP on the services list, you must install it: To add, Run->appwiz.cpl->Add Remove Windows components->IIS->Details->SMTP

jerjer
If you install an MTA (like windows' smtp service) and configure it to accept jobs without authentication (like the php/win32 smtp client needs) please, please make sure and double-check that this doesn't turn your machine into an open relay for all the email spammers in the world.
VolkerK
The point is that I don't want a SMTP service running on my machine. I want to mimic the UNIX implementation of mail, where the mail is handed off to sendmail and then forwarded to a server that doesn't necessarily reside on my machine. I know this is possible and I don't understand what I'm doing wrong.
Alex Ciminian
The behaviour of php's mail() depends on how the source was compiled. There's a win32 implementation and one for all other systems. The win32 implementation simply doesn't look for an application to inject the message into the MTA (/usr/sbin/sendmail) but uses its own (very simplistic) MTA. If your PHP version was compiled with this win32 implementation there's nothing you can do to let mail() recognize the sendmail_path parameter.
VolkerK
This is what I was afraid of, but it seems that it isn't true. In phpinfo() it says that it was compiled using the win32 implementation, and it works so I'm not sure what to say about the manual :).
Alex Ciminian
Oooops! I was completely wrong. Yes, according to the manual _and_ the php source code sendmail_path can also be used with the win32 build (and that code has been there for quite some time).
VolkerK
A: 

I am not sure if this helps or not, what i used to do in these scenarios was to setup , outlook on my machine and have it set to get emails from the pop every 5 mins or so, that way my ip/machine was authenticated against the pop and if i just set the :

SMTP = localhost
smtp_port = 25

in php.ini , the mail function worked fine. So in your case just set your outlook to work with a pop and use that smtp in php.ini and hopefully it should work. I havent tested this will GMail though.

Sabeen Malik
A: 

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

...unless you're using a plugin that changes this behaviour:
http://community.elgg.org/pg/plugins/costelloc/read/16498/phpmailer

VolkerK
True, but the I was contracted only to fix a (large :) list of bugs, not to rewrite the codebase :).
Alex Ciminian
As I understand it, this plugin already provides that functionality ...no rewrite necessary. On the other hand I had to look up "elgg" on google, so what do I know? ;-)
VolkerK
+2  A: 

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!

Alex Ciminian
Today I Learned Something New .... :D
VolkerK