This question already has an answer here:
I was trying to setup a contact form on my website. I have downloaded an example.
In this contact form, there is a $EmailFrom in the email message. Now, I wanna add this $EmailFrom to the sender field in the email that's sent.
I tried:
$EmailFrom = "$EmailFrom"
;
But I looks like that is not gonna work ;(
<?php
$EmailFrom = "test@hotmail.com";
$EmailTo = "info@mydomain.nl";
$Subject = "Contactformulier";
$Name = Trim(stripslashes($_POST['Name']));
$Tel = Trim(stripslashes($_POST['Tel']));
$Email = Trim(stripslashes($_POST['Email']));
$Message = Trim(stripslashes($_POST['Message']));
// validation
$validationOK=true;
if (!$validationOK) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
exit;
}
// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "
";
$Body .= "Tel: ";
$Body .= $Tel;
$Body .= "
";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "
";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "
";
// send email
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
// redirect to success page
if ($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=contactthanks.php\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
?>
I expected this: email sender
</div>