adding a name to the mail function when sending an email

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
hame22
Forum Contributor
Posts: 214
Joined: Wed May 11, 2005 5:50 am

adding a name to the mail function when sending an email

Post by hame22 »

Hi

My site offers news stories.

I am attempting to implement a "email a friend this article" feature allowing someone to email the link to a particular news item to a friend.

This works fine

However what I would like the sent email to do is have the users name or email address in the "from" field rather than my postmaster address. I have the users email address and name in variables.

Does anyone know how to achieve this?

Thanks in advance
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

You would set your from header to the senders email address.

Code: Select all

$headers = 'FROM: '.$usersemail."\r\n";

mail($to,$subject,$body,$headers);
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Post Reply