I am having problems changing the 'from' email header in the following script. Everthing else works ok but the from line in the email received is the server name and not admin@mywebsite.com:
ini_set("sendmail_from", " admin@mywebsite.com ");
$adminSendTo = "admin@mywebsite.com";
$adminSubject = "Contact Form";
$adminMessage = "Contact Form: $subfirstname $sublastname Email: $subemail Subject of feedback: $subsubject Comments: $subcommentquestion
";
$adminHeaders = "From: My website Contact Form
";
$adminHeaders = "Reply-To: admin@mywebsite.com";
mail($adminSendTo, $adminSubject, $adminMessage, $adminHeaders);
Do I need to change settings in the php.ini file for this to work?
Actually, you don't provide any "From" field.
By writing:
$adminHeaders = "From: My website Contact Form
";
$adminHeaders = "Reply-To: admin@mywebsite.com";
you assign the "From..." value to $adminHeaders
, then overwrite just on the next line by a new value "Reply-To...".
Instead, you should write:
$adminHeaders = "From: My website Contact Form
";
$adminHeaders .= "Reply-To: admin@mywebsite.com";
Here, "Reply-To..." will be concatenated to the actual value of $adminHeaders
, instead of overwriting it.
$adminHeaders = "From: My website Contact Form <contact@your-contact-site.com>
";
$adminHeaders .= "Reply-To: admin@mywebsite.com";
You clobbered the data!
Use .= to concatenate the strings together.
If you use "$var = some_value;" twice then only the second occurrence will count.