mayfair Posted October 1, 2009 Share Posted October 1, 2009 Hello Guys Im trying to send a plain text email using the mail() function but im having problems with display names. Im trying to send to "Someone <someone@example.com>" but it never gets there. When I CC a copy to myself, I see that it has only sent to "Someone" - it misses the actual email address. Ive been reading the documentation, and it states: Note: The Windows implementation of mail() differs in many ways from the Unix implementation... ...Second, the custom headers like From:, Cc:, Bcc: and Date: are not interpreted by the MTA in the first place, but are parsed by PHP. As such, the to parameter should not be an address in the form of "Something <someone@example.com>". The mail command may not parse this properly while talking with the MTA. Could this be the reason PHP is not sending the email? It's really important that I can work this out, because the "display name" is actually a bit of code that tells some web-import software what to do with the email. Without it, it won't work. The last part of my mail code is as follows: <?php $headers= 'To: GM-WEBIMPORT <xxx@xxx.com>'."\r\n"; $headers.= 'From: xxx@xxx.com'."\r\n"; $headers.= 'Cc: me@xxx.com'."\r\n"; mail($to,$subject,$message,$headers); ?> Quote Link to comment Share on other sites More sharing options...
Bricktop Posted October 1, 2009 Share Posted October 1, 2009 Hi mayfair, You may have already seen/tried the below but they may be of some help: $input = 'GM-WEBIMPORT <xxx@xxx.com>'; $to = trim(preg_replace("/([\w\s]+)<([\S@._-]*)>/", " $2", $input)); The above takes the $input of GM-WEBIMPORT <xxx@xxx.com> and turns it into xxx@xxx.com, depending on how your script functions this may be of use. Or: $additional_parameters Apparently, you can set a To: address in the $additional_parameters variable which will list the address in RFC-2822 format meaning you can use GM-WEBIMPORT <xxx@xxx.com>. Again, not sure if it's of any use to you. Hope this helps. Quote Link to comment Share on other sites More sharing options...
Bricktop Posted October 1, 2009 Share Posted October 1, 2009 Forgot to add, using the $additional_parameters option still requires a valid To: address using the $to parameter. Quote Link to comment Share on other sites More sharing options...
mayfair Posted October 1, 2009 Author Share Posted October 1, 2009 Hello Bricktop (great name btw ) I have tried both the suggestions you have mentioned, the first option output "GM-" only. The second one is an interesting idea. It didn't work by just specifying the To: address in the $to field and $additional_parameters, but I think it's a step in the right direction. There must be a workaround for Windows systems; this is surely a sommon problem? Unfortunately most of the forum posts/documentation I can find so far just states it is a problem and has no information on a possible workaround! Quote Link to comment Share on other sites More sharing options...
Bricktop Posted October 1, 2009 Share Posted October 1, 2009 Hi mayfair, thanks hehe I got both examples from the user contributed code over at http://us2.php.net/manual/en/function.mail.php, I agree that $additonal_parameters is the way forward but I can't find any usage examples either, I'm guessing something like: $to = 'xxx@xxx.com'; $additonal_parameters = 'To: GM-WEBIMPORT <xxx@xxx.com>'; mail($to, $subject, $headers, $additional_parameters); Another thought, and I doubt it would work, but how about replacing < and > with <\; and >\; Quote Link to comment Share on other sites More sharing options...
mayfair Posted October 1, 2009 Author Share Posted October 1, 2009 $to = 'xxx@xxx.com'; $additonal_parameters = 'To: GM-WEBIMPORT <xxx@xxx.com>'; mail($to, $subject, $headers, $additional_parameters); Yeah that's what I tried without success. I've also tried your other suggestion of replacing < and > with <\; and >\; but it didn't make a difference. Actually, I think it threw a 550 error and said the address was invalid or something. I will keep digging around trying to find some more examples, but if anyone else has any suggestions please feel free to contribute. Ive totally run out of ideas! Quote Link to comment Share on other sites More sharing options...
Bricktop Posted October 1, 2009 Share Posted October 1, 2009 Hi mayfair, Some other areas worth investigating may be using sockets to interface directly with the SMTP server and send the mail that way. Or, is there any way you could move this script (or the mailer part) to a UNIX server? Quote Link to comment Share on other sites More sharing options...
mayfair Posted October 1, 2009 Author Share Posted October 1, 2009 No unfortunately we manage our own dedicated servers which are all running Windows. Also, I have to work with a particularly obnoxious network administrator who doesn't know his arse from his elbow and getting this past him will likely take decades. Appreciate your suggestions though Quote Link to comment Share on other sites More sharing options...
sawade Posted October 2, 2009 Share Posted October 2, 2009 What about using PEAR? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.