Page 1 of 1

php mail function to add "nickname"?

Posted: Fri Mar 05, 2010 7:59 am
by lellis2k
Hi Guys,

I'm using the php "mail" function to send emails out and wondered if I can set the name when I do this?

To clarify, I can set the email address that it comes from e.g. john.smith@example.com using the header "From:"
but I would like to also set a name e.g. "John Smith" which would show up at the recipent end.

Most of the time when people get emails you see a name like this rather than the email address.

How can I make this happen, I would have thought it would be a header like "Name" or something but can't find anything about it.

My Code:

Code: Select all

$to= "customer@somewhere.com";
$message = "Hello, how are things?";
$subject = "Example Subject";
$headers = "MIME-Version: 1.0\r\n"; 
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n"; 
$headers  .= "From: john.smith@example.com\r\n"; 
 
mail($to, $subject, $message, $headers);

Re: php mail function to add "nickname"?

Posted: Fri Mar 05, 2010 8:37 am
by papa
Well either you store it in a user table in a database or use regular expression. But it's not likely all people have an email address like John Smith.

Re: php mail function to add "nickname"?

Posted: Fri Mar 05, 2010 8:41 am
by lellis2k
The email address isn't "john smith", you send the email address as well as a nickname. For example when I send emails from my googlemail everyone else sees Leigh Ellis, but if they click into it they will see it came from ellislives@gmail.com

Re: php mail function to add "nickname"?

Posted: Fri Mar 05, 2010 8:44 am
by papa
And in your settings you write your name which is stored in a db.

Re: php mail function to add "nickname"?

Posted: Fri Mar 05, 2010 9:35 am
by lellis2k
ah okay, so does google host that database of gmail nicknames?

If this is the case how would I go about setting up this database and linking it to the emails?