Avatar of dban00b
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_subject,$mail_message,$mail_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_subject,$mail_message,$mail_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@example.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.
PHPMicrosoft IIS Web ServerEmail Protocols

Avatar of undefined
Last Comment
dban00b

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Chris Dent

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
dban00b

ASKER
Thanks, I see that it is indeed a known bug with PHP on a windows based machine.

And the work-around you mentioned does work.

Your help has saved me hundreds of hours of internet surfing.
fblack61