ilottl Posted August 5, 2010 Share Posted August 5, 2010 I have the simple code below which seems to have worked on forms from a contact page on a website. Unfortunately, it seems to only send the forms if all fields are entered. I have played with the code but cannot seem to get it to send any field that has been completed on submit. Can someone help please? <?php $emailAddress = "bigL@gmail.com"; $thankyouPage = ""; session_start(); if (!empty($_POST)) { foreach ($_POST as $key=>$value) { $_POST[$key] = stripslashes($_POST[$key]); $_POST[$key] = htmlspecialchars($_POST[$key],ENT_QUOTES); } } if (isset($_POST['send']) AND isset($_SESSION['msgCount'])) { if ($_SESSION['msgCount'] >= "3") $alert = "Only 3 messages can be s +ent per session."; if (empty($alert)) { $_SESSION['msgCount']++; putenv('TZ=EST5EDT'); // eastern time $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n" +; $message = "<table cellpadding='5' border='1'>"; foreach ($_POST as $key => $value) if (!preg_match("(^send)",$key)) { $value = wordwrap($value,65,"<br />"); $message .="<tr><td><b>$key</b></td><td>$value</td></tr>"; } $message .= "</table>"; $message .= "<br />Time of the message: ".date(" F d h:ia")."<br +/>"; $message .= "IP Address: ".$_SERVER['REMOTE_ADDR']."<br />"; $message .= "Hostname: ".gethostbyaddr($_SERVER['REMOTE_ADDR'])."< +br />"; $subject = $_SERVER['HTTP_HOST']." Message"; mail($emailAddress,$subject,$message,$headers); if (!empty($thankyouPage)) { header('location: '.$thankyouPage); die(); } unset($_POST); $alert = "Your enquiry has been sent, we will respond as soon as p +ossible."; } } if (!isset($_SESSION['msgCount'])) $_SESSION['msgCount'] = 0; ?> Quote Link to comment Share on other sites More sharing options...
AdRock Posted August 5, 2010 Share Posted August 5, 2010 Don't quote me as I do forms a different way but what about this line? if (!empty($_POST)) { I'm pretty sure that won't pass unless all fields are entered Quote Link to comment Share on other sites More sharing options...
ilottl Posted August 5, 2010 Author Share Posted August 5, 2010 Thanks for that, so if if (!empty($_POST)) { is the problem is there any way to assign a value, eg "Not completed" to the empty $_POST, eg if (!empty($_POST)) THEN $_POST = "N/A" { Quote Link to comment Share on other sites More sharing options...
ilottl Posted August 6, 2010 Author Share Posted August 6, 2010 Here is a link to the real page which I have had to put default values in for every field.. http://www.cartagesolutions.co.nz/quote.php I have also tried removing the empty part of the script but makes no difference. The form only seems to work if all fields are completed. Help!! Any ideas?? Quote Link to comment Share on other sites More sharing options...
PradeepKr Posted August 8, 2010 Share Posted August 8, 2010 foreach($_POST as $key => $value) { if( ! isset($value) ) $_POST{$key} = "N/A"; } if (!empty($_POST)) { ............ } Quote Link to comment 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.