homepage Welcome to WebmasterWorld Guest from 54.237.249.10
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Redirect Outgoing Sendmail to Development Email Address
don't want to send out emails on development server
chadmg




msg:1316417
 8:38 pm on Jan 12, 2006 (gmt 0)

I would like to have sendmail on my development server send to a testing email address instead of it's intended recipient. That way I can set up the PHP script exactly like I would on the live server, but test that it's sending out the correct email.

Does anyone know how to do this?

 

jatar_k




msg:1316418
 8:44 pm on Jan 12, 2006 (gmt 0)

I have always just used a test address and then just change the address on the live server.

I have done this by storing variables that change from server to server in a config file. That allows all the scripts to be exactly the same and just the values in each config file are different.

chadmg




msg:1316419
 10:09 pm on Jan 12, 2006 (gmt 0)

Well I have some emails where the TO field is generated dynamically and it would also be nice to test that the TO field is being set correctly. Yes, I could set the TO field to my email address and put the dynamically created TO field in the message and then change it right before I send it live. But I'd rather not. I'm also buliding entire systems in development with many different pages sending emails. I don't want to have to make sure I fix them all before going live.

A solution could be to create my own mail() function like mymail() that automatically replaces the TO field with my email and puts the original TO, CC, and BCC into X-original-to, etc in the header. Unfortunately, I have thousands of pages out there already and I would like this to be a global thing.

I found a solution that would do what I'm looking for here:
[blog.phpdoc.info...]

It basically changes the sendmail_path line in php.ini to:
sendmail_path=/usr/local/bin/trapmail

Then you create the /usr/local/bin/trapmail file like so:
formail -R to X-original-to -R cc X-original-cc -R bcc X-original-bcc -f -A "To: devteam@example.com" ¦ /usr/sbin/sendmail -t -i

This uses the formail command to change the headers and sends it to sendmail.

Unfortunately, I still have some problem because it's still sending to the original to address. If I get it to work I'll share.

If anyone else gets it to work, please let me know. Thanks.

chadmg




msg:1316420
 9:44 pm on Jan 17, 2006 (gmt 0)

Update:

This works just fine. The script I was using to test uses sendmail, but not through the php mail() function. Therefore, php wasn't involved to send it to trapmail. When I created a new script, it worked perfectly.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved