dban00b
asked on
PHP mail function using IIS SMTP failing on Friendly Name
I have a very simple piece of code trying to send out an email. This works:
$mail_to = "test@example.com";
$mail_subject = "Test Subject";
$mail_message = "Test Message";
$mail_from = "admin@example.com";
$mail_headers = "From: ".$mail_from."";
mail($mail_to,$mail_subjec t,$mail_me ssage,$mai l_headers) ;
However when I try to add a friendly name to the From header like this it fails:
$mail_to = "test@example.com";
$mail_subject = "Test Subject";
$mail_message = "Test Message";
$mail_from = "admin@example.com";
$mail_headers = "From: Admin <".$mail_from.">";
mail($mail_to,$mail_subjec t,$mail_me ssage,$mai l_headers) ;
The error return by php is:
Warning: mail() [function.mail]: SMTP server response: 501 5.5.4 Invalid Address in D:\www\testmail.php on line 10
And the log in IIS's SMTP server shows:
2009-03-13 20:14:44 127.0.0.1 web01 SMTPSVC1 web01 127.0.0.1 0 HELO - +web01 250 0 30 11 0 SMTP - - - -
2009-03-13 20:14:44 127.0.0.1 web01 SMTPSVC1 web01 127.0.0.1 0 MAIL - +FROM:<Admin+<admin@exampl e.com>> 501 0 27 71 0 SMTP - - - -
2009-03-13 20:14:44 127.0.0.1 web01 SMTPSVC1 web01 127.0.0.1 0 QUIT - web01 240 0 55 4 0 SMTP - - - -
Showing that it's (re?)wrapping the from parameter in <> which is, of course, malformed.
I have no idea which piece of the puzzle needs to be fixed or how to go about it.
$mail_to = "test@example.com";
$mail_subject = "Test Subject";
$mail_message = "Test Message";
$mail_from = "admin@example.com";
$mail_headers = "From: ".$mail_from."";
mail($mail_to,$mail_subjec
However when I try to add a friendly name to the From header like this it fails:
$mail_to = "test@example.com";
$mail_subject = "Test Subject";
$mail_message = "Test Message";
$mail_from = "admin@example.com";
$mail_headers = "From: Admin <".$mail_from.">";
mail($mail_to,$mail_subjec
The error return by php is:
Warning: mail() [function.mail]: SMTP server response: 501 5.5.4 Invalid Address in D:\www\testmail.php on line 10
And the log in IIS's SMTP server shows:
2009-03-13 20:14:44 127.0.0.1 web01 SMTPSVC1 web01 127.0.0.1 0 HELO - +web01 250 0 30 11 0 SMTP - - - -
2009-03-13 20:14:44 127.0.0.1 web01 SMTPSVC1 web01 127.0.0.1 0 MAIL - +FROM:<Admin+<admin@exampl
2009-03-13 20:14:44 127.0.0.1 web01 SMTPSVC1 web01 127.0.0.1 0 QUIT - web01 240 0 55 4 0 SMTP - - - -
Showing that it's (re?)wrapping the from parameter in <> which is, of course, malformed.
I have no idea which piece of the puzzle needs to be fixed or how to go about it.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
And the work-around you mentioned does work.