Jump to content

Form sends, but error message remains.


Carelkat
Go to solution Solved by ginerjm,

Recommended Posts

<?php
$suspect = false;
$pattern = '/Content-Type:|Bcc:|Cc:/i';

function isSuspect($val, $pattern, &$suspect) {
	if  (is_array($val)) {
		foreach ($val as $item) {
			isSuspect($item, $pattern, $suspect);
		}
	} else {
		if (preg_match($pattern, $val)) {
			$suspect = true;
		}
	}
}
isSuspect($_POST, $pattern, $suspect);
		if (is_array($val)) {
			foreach ($val as $item) {
		 	isSuspect($item, $pattern, $suspect);
			}
		} else {
			if (preg_match($pattern, $val)) {
				$suspect = true;
			}
		}

isSuspect($_POST, $pattern, $suspect);

if (!$suspect) {
	foreach ($_POST as $key => $value) {
	$temp = is_array($value) ? $value : trim($value);
	if (empty($temp) && in_array($key, $required)) {
		$missing[] = $key;
		$$key = '';	
	} elseif (in_array($key, $expected)) {
		$$key = $temp;
	}
	}
}
if (!$suspect && !empty($b_mail)) {
	$validemail = filter_input(INPUT_POST, 'b_mail', FILTER_VALIDATE_EMAIL);
	if ($validemail) {
	$headers .= "\r\nReply-to: $validemail";
	} else  {
		$errors['b_mail'] = true;
	}

}
if (!$suspect && !$missing && !$errors) {
	$message = '';
	foreach ($expected as $item) {
		if (isset($$item) && !empty($$item)) {
			$val = $$item;
		} else {
			$val = 'Not selected';
		}
	if (is_array($val)) {
		$val = implode(', ', $val);
	}
	$item = str_replace(array('_', '-'), ' ', $item);
	$message .= ucfirst($item) . ": $val\r\n\r\n";
	}
	$message = wordwrap($message, 70);
	
	$mailSent = mail($to, $subject, $message, $headers, $authenticate);
	if (!$mailsent) {
		$errors['mailfail'] = true;
	}
}
	?>
<?php if (($_POST && $suspect) || ($_POST && isset($errors['mailfail']))) { ?>
	 <p class="warning">Sorry your message could not be sent.</p>
	 <?php echo ($suspect)?>
    <?php } elseif ($errors || $missing) { ?>
    <p class="warning">Please fix the item(s) indicated.</p>
    <?php }?>
<?php
$errors = array();
$missing = array();
if (isset($_POST['submit'])) {
	$to = "Carel Venter <bookings@bushveldgolf.co.za>";
	$subject = "Booking";
	$expected = array('b_name', 'b_surn', 'b_tele', 'b_mail', 'b_acco', 'b_golf', 'b_nong', 'b_pack', 'b_courses', 'b_dfrom', 'b_dto');
	$required = array('b_name', 'b_surn', 'b_tele', 'b_mail', 'b_acco', 'b_golf', 'b_pack', 'b_courses', 'b_dfrom', 'b_dto');
	if (!isset($_POST['b_courses'])) {
		$_POST['b_courses'] = array();
	}
	if(!is_array($_POST['b_courses'])) 
	{
		$_POST['b_courses'] = array($_POST['b_courses']);
	}
	$minimumChecked = 1;
	if (count($_POST['b_courses']) < $minimumChecked) {
		$errors['b_courses'] = true;}
	$headers = "From:" .$b_mail. "\r\n";
	$headers .= "Content-Type: text/plain; charset=utf-8\r\n";
	$authenticate = '-fcarel@bushveldgolf.co.za';
	require './php_include/mail_process2.php';
	if($mailsent) {
		//echo "Thank you, I wil get back to you soon.";
		header('Location:/thanks.php');
		exit;
	}
}
?>

Hi, thank you for your time.

 

I have this booking form, and its sends the email perfect. I get it with all the fields. The error message however keeps on appearing and it doesn't go to the thank you page.

 

I include the top of the page, the top of the form, and the mail process form. I would really appreciate help.

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.