Link to home
Start Free TrialLog in
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.
ASKER CERTIFIED SOLUTION
Avatar of Chris Dent
Chris Dent
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dban00b
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.