[SOLVED] setting a specific From header in the mail function

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
jasongr
Forum Contributor
Posts: 206
Joined: Tue Jul 27, 2004 6:19 am

[SOLVED] setting a specific From header in the mail function

Post by jasongr »

Hello

I am using the mail() function to send email.
I would like to set the mail headers such that when I will receive an email from someone, the From field will look like:
From: John Smith
where Jogn Smith would be the name of the person (available to me when I call the mail function.

However, when I reply to the mail, the reply will be sent to John Smith's mail address.

Here is my code:

Code: Select all

$name = 'John Smith'
// $email holds the email address of John Smith
$header = "From: " .$email;

$message = "Hello, this is a test";

mail('test@test.com', 'this is the subject', $message, $header);
My question is this:
How can I use the $name variable with the mail headers to acheive what I want.

regards
Jason
User avatar
liljester
Forum Contributor
Posts: 400
Joined: Tue May 20, 2003 4:49 pm

Post by liljester »

try this format:
From: liljester <liljester@somewhere.org>

Code: Select all

$header = "From: $name <$email>";
jasongr
Forum Contributor
Posts: 206
Joined: Tue Jul 27, 2004 6:19 am

Post by jasongr »

thank you, It works
Post Reply