isaacr25
asked on
Php email not sending field values
Please see the attached php email script. When I submit this form (www.mwebdev.com/stat/employment.html), I get the email successfully. However, I only get the labels, and not the field values. The php script only has a few of the first fields to this point. I will add them after I get the email working successfully. Thanks for your help in advance.
<?php
// get posted data into local variables
$EmailFrom = "website@domainhere.com";
$EmailTo = "realemailhere.com";
$Subject = "Email from Website";
$Name = Trim(stripslashes($_POST['name']));
$Phone = Trim(stripslashes($_POST['phone1']));
$Email = Trim(stripslashes($_POST['email']));
// 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 .= "\n";
$Body .= "Home Phone: ";
$Body .= $phone1;
$Body .= "\n";
$Body .= "Office Phone: ";
$Body .= $phone2;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $email;
$Body .= "\n";
$Body .= "Address: ";
$Body .= $address;
$Body .= "\n";
$Body .= "City: ";
$Body .= $city;
$Body .= "\n";
$Body .= "State: ";
$Body .= $state;
$Body .= "\n";
$Body .= "Zip: ";
$Body .= $zip;
$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=appsent.html\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
?>
PHP is case sensitive for variables. See the attached.
<?php
// get posted data into local variables
$EmailFrom = "website@domainhere.com";
$EmailTo = "realemailhere.com";
$Subject = "Email from Website";
$name = Trim(stripslashes($_POST['name']));
$phone1 = Trim(stripslashes($_POST['phone1']));
$email = Trim(stripslashes($_POST['email']));
// 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 .= "\n";
$Body .= "Home Phone: ";
$Body .= $phone1;
$Body .= "\n";
$Body .= "Office Phone: ";
$Body .= $phone2;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $email;
$Body .= "\n";
$Body .= "Address: ";
$Body .= $address;
$Body .= "\n";
$Body .= "City: ";
$Body .= $city;
$Body .= "\n";
$Body .= "State: ";
$Body .= $state;
$Body .= "\n";
$Body .= "Zip: ";
$Body .= $zip;
$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=appsent.html\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
?>
You'll now have name, phone1, and email working. Others you will need to add. Just remember to check the capitalisation!
ASKER
Only my labels are capitalized. As far as I can tell, my variables are lower-case. Where do you see different in the code... I can't see the difference between my code and yours. Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER