PHP form to email - changing 'From' address
Posted: Fri Jan 14, 2011 8:46 am
Hi all, Please could somebody help.
I have an enquiry form, that uses PHP to generate an email. Here's my code...
Please could somebody tell me how I change the 'From' email address (currently "Enquiry") so that it pulls in the email address input by the person making the enquiry:
I have an enquiry form, that uses PHP to generate an email. Here's my code...
Please could somebody tell me how I change the 'From' email address (currently "Enquiry") so that it pulls in the email address input by the person making the enquiry:
Code: Select all
<?php
// Website Contact Form Generator
// http://www.tele-pro.co.uk/scripts/contact_form/
// This script is free to use as long as you
// retain the credit link
// get posted data into local variables
$EmailFrom = "Enquiry";
$EmailTo = "mailbox@mariawattfoundation.org";
$Subject = "Maria Watt Foundation website enquiry";
$name = Trim(stripslashes($_POST['name']));
$email = Trim(stripslashes($_POST['email']));
$telephone = Trim(stripslashes($_POST['telephone']));
$comments = Trim(stripslashes($_POST['comments']));
// validation
if (strtolower($_POST['code']) != 'mwf') {die('Sorry, you have entered the wrong code. This measure is in place to prevent spam via this website. Please go back and enter the correct code.');}
$validationOK=true;
if (Trim($email)=="") $validationOK=false;
if (!$validationOK) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=http://www.mariawattfoundation.org/error.html\">";
exit;
}
// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $name;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $email;
$Body .= "\n";
$Body .= "Telephone: ";
$Body .= $telephone;
$Body .= "\n";
$Body .= "Comments: ";
$Body .= $comments;
$Body .= "\n";
// send email
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
// redirect to success page
if ($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=http://www.mariawattfoundation.org/thankyou.html\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=http://www.mariawattfoundation.org/error.html\">";
}
?>