Page 1 of 1

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

Posted: Wed Jul 28, 2004 8:57 am
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

Posted: Wed Jul 28, 2004 9:06 am
by liljester
try this format:
From: liljester <liljester@somewhere.org>

Code: Select all

$header = "From: $name <$email>";

Posted: Wed Jul 28, 2004 9:14 am
by jasongr
thank you, It works