Jump to content

Mail() Display Name Problem


mayfair

Recommended Posts

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); 
?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Hello Bricktop (great name btw  :D)

 

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!

Link to comment
Share on other sites

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 &lt\; and &gt\;

Link to comment
Share on other sites

$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 &lt\; and &gt\; 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!

Link to comment
Share on other sites

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  :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.