Click here to Skip to main content
15,891,902 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm not all up-ons with this web development stuff but I'm part way through putting together a website and have come across an irritating problem:

mail("somebody@someaddress.com", $subject, $message, 'From: SomeName <someotherEmail@address.com>' )


It complains about an invalid address, which I know to be the From field I have to set in the header. So what obvious thing am I missing? It works if I just put the email address by itself, but when I try to put a name to it, it blows up in my face!
Posted

I found a very strange work around to the problem. Calling ini_set("sendmail_from", ""); just prior to calling mail mysteriously allows you to use the friendly name. It's madness.
 
Share this answer
 
Comments
Peter_in_2780 12-Aug-10 22:44pm    
Madness indeed! Good to see you've got a workaround.
The fourth arg to mail() is "additional headers", according to the manual. If used to specify a "From:" header, the rest of the line needs to parse as an email address without spaces and angles. "Interpretation" of the sender's email (e.g. adding "SomeName") is done by the recipient's mail agent, using his/her address book.
If the parsing wasn't done, it would open up a(nother) huge email forgery window, so you'll just have to live with sending a plain email address.
 
Share this answer
 
Comments
Anthony Mushrow 12-Aug-10 22:13pm    
After more searching is seems you're partially right. There is a bug in PHP on windows where it doesn't parse the friendly name thing correctly, it's actually mentioned at the bottom of this page:
http://php.net/manual/en/function.mail.php

Would have been nice to know sooner.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900