views:

997

answers:

2

I have two dedicated servers, one of which is configured for sending email out (SPF, DKIM, other domain whitelisting methods, etc). I need to send email from both servers, but I want to send mail from both servers through the server that's been set up for it.

It doesn't look like I can explicitly set an SMTP server directly in the mail function. Is there a way I can override the value set in php.ini, through .htaccess or something?

+2  A: 

I would recommend not using the mail command and using a pre-built PHP mailing solution. There are 2 great recommendations at the following: http://stackoverflow.com/questions/809924/is-this-the-correct-way-to-send-email-with-php/809995#809995

In using a pre-built solution, you can have all of your mail go to the same server if you choose.

Jordan S. Jones
just out of curiosity, how do these prebuilt mailing solutions get their mail delivered? direct socket connections? i would imagine they're not just wrappers for mail()....
Ian
With the ones I've used, you have your choice of transport. SMTP, which leverages PHP's socket functions, or Mail which leverages the underlying mail() command. I strongly recommend using the SMTP transport type because, if you were not aware of this, the mail() command can rewrite your email's FROM header to be that of the user the server is running as. E.g. User is Apache, Domain is yourdomain.com, Servername is www, it would change it to [email protected]. SMTP doesn't do this.
Jordan S. Jones
A: 

I would recommend using ezcMail for sending emails. It has a clean object oriented prebuilt mailing package which is highly configurable.

Shoan