Carelkat Posted February 26, 2014 Share Posted February 26, 2014 <?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. Quote Link to comment https://forums.phpfreaks.com/topic/286556-form-sends-but-error-message-remains/ Share on other sites More sharing options...
WebStyles Posted February 26, 2014 Share Posted February 26, 2014 can you post the error please? Quote Link to comment https://forums.phpfreaks.com/topic/286556-form-sends-but-error-message-remains/#findComment-1470811 Share on other sites More sharing options...
Carelkat Posted February 26, 2014 Author Share Posted February 26, 2014 It does not post an PHP error. Please look at the Booking page on bushveldgolf.co.za and fill it in. It just shows my error message, "Your message could not be send", but I get the message perfectly well. It does not want to go to the Thank you page. Quote Link to comment https://forums.phpfreaks.com/topic/286556-form-sends-but-error-message-remains/#findComment-1470814 Share on other sites More sharing options...
Solution ginerjm Posted February 26, 2014 Solution Share Posted February 26, 2014 I suspect it is because of your habit of using capitals in naming your variables. IMHO a very bad habit. $mailsent is the culprit. I think you meant to write $mailSent. Quote Link to comment https://forums.phpfreaks.com/topic/286556-form-sends-but-error-message-remains/#findComment-1470818 Share on other sites More sharing options...
WebStyles Posted February 26, 2014 Share Posted February 26, 2014 Ah! that was a nice catch ginerjm. I totally missed it. Quote Link to comment https://forums.phpfreaks.com/topic/286556-form-sends-but-error-message-remains/#findComment-1470819 Share on other sites More sharing options...
ginerjm Posted February 26, 2014 Share Posted February 26, 2014 My pet peeve about (inexperienced?) PHP programmers. Why use caps when you don't have to? Consequently I'm always on the lookout Quote Link to comment https://forums.phpfreaks.com/topic/286556-form-sends-but-error-message-remains/#findComment-1470820 Share on other sites More sharing options...
WebStyles Posted February 26, 2014 Share Posted February 26, 2014 ... plus the fact that they actually take longer to type because you have to hit that shift button. (I actually do use them, I like camelcase, just makes them a little bit easier to read) Quote Link to comment https://forums.phpfreaks.com/topic/286556-form-sends-but-error-message-remains/#findComment-1470821 Share on other sites More sharing options...
ginerjm Posted February 26, 2014 Share Posted February 26, 2014 Well, camelCase is what got the OP in trouble here. My preference is to keep 'em short and use _ scores. I'm wicked with that 3rd finger. Quote Link to comment https://forums.phpfreaks.com/topic/286556-form-sends-but-error-message-remains/#findComment-1470822 Share on other sites More sharing options...
Carelkat Posted February 26, 2014 Author Share Posted February 26, 2014 Thank you, thank you, thank you ginerjm. I went through the code over and over for about two days and could not find the mistake. And a thank you for a the lesson about the capital letters in naming my variables. That habit stopped a few minutes ago. Quote Link to comment https://forums.phpfreaks.com/topic/286556-form-sends-but-error-message-remains/#findComment-1470823 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.