php mail function to add "nickname"?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lellis2k
Forum Newbie
Posts: 3
Joined: Fri Mar 05, 2010 5:46 am

php mail function to add "nickname"?

Post 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);
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: php mail function to add "nickname"?

Post 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.
lellis2k
Forum Newbie
Posts: 3
Joined: Fri Mar 05, 2010 5:46 am

Re: php mail function to add "nickname"?

Post 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
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: php mail function to add "nickname"?

Post by papa »

And in your settings you write your name which is stored in a db.
lellis2k
Forum Newbie
Posts: 3
Joined: Fri Mar 05, 2010 5:46 am

Re: php mail function to add "nickname"?

Post 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?
Post Reply