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 <[email protected]>" 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 <[email protected]>". 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 <[email protected]>'."\r\n";
$headers.= 'From: [email protected]'."\r\n";
$headers.= 'Cc: [email protected]'."\r\n";

mail($to,$subject,$message,$headers); 
?>

Link to comment
https://forums.phpfreaks.com/topic/176165-mail-display-name-problem/
Share on other sites

Hi mayfair,

 

You may have already seen/tried the below but they may be of some help:

 

$input = 'GM-WEBIMPORT <[email protected]>';
$to = trim(preg_replace("/([\w\s]+)<([\S@._-]*)>/", " $2", $input));

 

The above takes the $input of GM-WEBIMPORT <[email protected]> and turns it into [email protected], 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 <[email protected]>.  Again, not sure if it's of any use to you.

 

Hope this helps.

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!

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 = '[email protected]';
$additonal_parameters = 'To: GM-WEBIMPORT <[email protected]>';

mail($to, $subject, $headers, $additional_parameters);

 

Another thought, and I doubt it would work, but how about replacing < and > with &lt\; and &gt\;

$to = '[email protected]';

$additonal_parameters = 'To: GM-WEBIMPORT <[email protected]>';

 

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!

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.