I have the following code which is taken from the php side of a basic html contact form:
<?php
session_start();
if(isset($_POST['fullname_1'])) {
include 'formsettings.php';
function died($error) {
echo "Sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
if(!isset($_POST['fullname_1']) || !isset($_POST['fullname_1'])) {
died('Sorry, there appears to be a problem with your form submission.');
}
$name_from = $_POST['fullname_1']; // required
$ip = $_SERVER['REMOTE_ADDR'];
$error_message = "";
$email_message = "Form details below.\r\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:");
return str_replace($bad,"",$string);
}
$email_message .= "Full name is: ".clean_string($name_from)."\r\n";
$email_message .="IP Address: ".clean_string($ip)."\n\n";
$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: $thankyou");
?>
<script>location.replace('<?php echo $thankyou;?>')</script>
<?php
}
die();
?>
It takes the value of the textbox fullname_1 where the fullname is entered and sends an email. and takes the user to a thank you page once submit is clicked.
However i want to add a condition where it decides the thank you page depending on the first three letters of the text enters so i have the following code:
$value = substr($name_from,0,3);
if (strtolower($value) === "abc"){
$thankyou = "../abc.html"; // male
}
elseif($value === "def"){
$thankyou = "../def.html"; // female
}
else{
$thankyou = "../xyz.html"; // no male, no female
}
When i add this code, the script stops functioning. Any help would be appreciated. Thanks.