tekgrl
asked on
help with php form
Hi all. This form worked fine when I just needed the first name and email validated. I now need first name, last name and email validated. Please help. PHP code attached.
<?php
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "me@myemail.com";
$email_subject = "Test";
function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form your submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['firstName']) ||
!isset($_POST['email'])) {
died('We are sorry, but there appears to be a problem with the form your submitted.');
}
$firstName = $_POST['firstName']; // required
$lastName = $_POST['lastName']; // required
$email_from = $_POST['email']; // required
$company = $_POST['company']; // required
$phone = $_POST['phone']; // required
$source = $_REQUEST['source'];
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "First Name: ".clean_string($firstName)."\n";
$email_message .= "Last Name: ".clean_string($lastName)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Company: ".clean_string($company)."\n";
$email_message .= "Phone: ".clean_string($phone)."\n";
$email_message .= "Source: ".clean_string($source)."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
header("Location: thanks.html");
}
?>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That's it! Thanks.
ASKER
Beautiful. Thanks!
// validation expected data exists
if(!isset($_POST['firstNam
!isset($_POST['email'])) {
died('We are sorry, but there appears to be a problem with the form your submitted.');
}