mallen Posted August 24, 2008 Share Posted August 24, 2008 This form is not sending the email. It doesn't give any error. If you miss a field it will tellyou. But if you fill them out it still says The following required fields have not been filled in: Is there any missing here? I know I had this form and others working for a client and maybe something got changed. // process the email if (array_key_exists('send', $_POST)) { $to = '[email protected]'; // use your own email address $subject = 'Register'; // list expected fields $expected = array('firstname','lastname','email','company','address','city','state','zipcode','country','phone', 'cellphone','fax','status','password','interests'); // set required fields $required = array('firstname','lastname','email'); // create empty array for any missing fields $missing = array(); // assume that there is nothing suspect $suspect = false; // create a pattern to locate suspect phrases $pattern = '/Content-Type:|Bcc:|Cc:/i'; // function to check for suspect phrases function isSuspect($val, $pattern, &$suspect) { // if the variable is an array, loop through each element // and pass it recursively back to the same function if (is_array($val)) { foreach ($val as $item) { isSuspect($item, $pattern, $suspect); } } else { // if one of the suspect phrases is found, set Boolean to true if (preg_match($pattern, $val)) { $suspect = true; } } } // check the $_POST array and any sub-arrays for suspect content isSuspect($_POST, $pattern, $suspect); if ($suspect) { $mailSent = false; unset($missing); } else { // process the $_POST variables foreach ($_POST as $key => $value) { // assign to temporary variable and strip whitespace if not an array $temp = is_array($value) ? $value : trim($value); // if empty and required, add to $missing array if (empty($temp) && in_array($key, $required)) { array_push($missing, $key); } // otherwise, assign to a variable of the same name as $key elseif (in_array($key, $expected)) { ${$key} = $temp; } } } // validate the email address if (!empty($email)) { // regex to ensure no illegal characters in email address $checkEmail = '/^[^@]+@[^\s\r\n\'";,@%]+$/'; // reject the email address if it doesn't match if (!preg_match($checkEmail, $email)) { array_push($missing, 'email'); } } // go ahead only if not suspect and all required fields OK if (!$suspect && empty($missing)) { // set default values for variables that might not exist $subscribe = isset($subscribe) ? $subscribe : 'Nothing selected'; $interests = isset($interests) ? $interests : array('None selected'); $characteristics = isset($characteristics) ? $characteristics : array('None selected'); // build the message $message = "First Name: $firstname\n\n"; $message .= "Last Name: $lastname\n\n"; $message .= "Email: $email\n\n"; $message .= "Company: $company\n\n"; $message .= "Address: $address\n\n"; $message .= "City: $city\n\n"; $message .= "State/Providence: $state\n\n"; $message .= "Zipcode: $zipcode\n\n"; $message .= "Country: $country\n\n"; $message .= "Phone: $phone\n\n"; $message .= "Cell Phone: $cellphone\n\n"; $message .= "Fax: $fax\n\n"; $message .= 'Interests: '.implode(', ', $interests)."\n\n"; // limit line length to 70 characters $message = wordwrap($message, 70); // create additional headers $additionalHeaders = 'From: [email protected]>'; if (!empty($email)) { $additionalHeaders .= "\r\nReply-To: $email"; } // send it $mailSent = mail($to, $subject, $message, $additionalHeaders); if ($mailSent) { // $missing is no longer needed if the email is sent, so unset it unset($missing); //$query = "INSERT INTO members (id, firstname, email) //VALUES (0,'{$_POST['firstname']}','{$_POST['email']}')"; $query = "INSERT INTO members (id, firstname, lastname, email, company, address, city, state, zipcode, country, phone, cellphone, fax, status, password) VALUES (0,'{$_POST['firstname']}','{$_POST['lastname']}','{$_POST['email']}','{$_POST['company']}','{$_POST['address']}','{$_POST['city']}','{$_POST['state']}','{$_POST['zipcode']}','{$_POST['country']}','{$_POST['phone']}','{$_POST['cellphone']}','{$_POST['fax']}','{$_POST['status']}','{$_POST['password']}')"; if (@mysql_query ($query)) { print ''; } else { print "<p>Could not enter data becuase: <b>" . mysql_error() ."</b>. The query was $query.</p>"; } mysql_close(); } } } ?> <?php if (isset($missing)) { echo '<p>The following required fields have not been filled in:</p>'; echo '<ul>'; foreach($missing as $item) { echo "<li>$item</li>"; } echo '</ul>'; } elseif ($_POST && $mailSent) { echo '<p><strong>Your message has been sent. Thank you for your feedback.</strong></p>'; } ?> <form id="feedback" method="post" action=""> <table border="0"> <tr> <td height="35" colspan="2" class="subheader">Register Form</td> <td height="25"> </td> <td height="25"> </td> </tr> <tr> <td height="25"> </td> <td height="35"> </td> <td height="25"> </td> <td height="25"> </td> </tr> <tr> <td width="98" height="25"> <label for="firstname">First Name: </label></td> <td width="195" height="35"><input name="firstname" id="firstname" type="text" class="formbox" <?php if (isset($missing)) { echo 'value="'.htmlentities($_POST['firstname']).'"';} ?>/> </td> <td width="72" height="25"><label for="lastname">Last Name:</label></td> <td width="247" height="25"><input name="lastname" id="lastname" type="text" class="formbox" <?php if (isset($missing)) { echo 'value="'.htmlentities($_POST['lastname']).'"';} ?>/></td> </tr> <tr> <td height="35"> <label for="Email">Email:</label></td> <td height="10"> <input name="email" id="email" type="text" class="formbox" <?php if (isset($missing)) { echo 'value="'.htmlentities($_POST['email']).'"';} ?>/></td> <td height="10"><label for="company">Company: </label></td> <td height="10"> <input name="company" id="company" type="text" class="formbox" <?php if (isset($missing)) { echo 'value="'.htmlentities($_POST['company']).'"';} ?>/></td> </tr> <tr> <td height="35"><label for="address">Address: </label></td> <td> <input name="address" id="address" type="text" class="formbox" <?php if (isset($missing)) { echo 'value="'.htmlentities($_POST['address']).'"';} ?>/></td> <td> <label for="city">City:</label> </td> <td> <input name="city" id="city" type="text" class="formbox" <?php if (isset($missing)) { echo 'value="'.htmlentities($_POST['city']).'"';} ?>/></td> </tr> <tr> <td height="35"><label for="state">State / Providence: </label></td> <td> <input name="state" id="state" type="text" class="formbox" <?php if (isset($missing)) { echo 'value="'.htmlentities($_POST['state']).'"';} ?>/></td> <td> <label for="zipcode">Zip code:</label></td> <td> <input name="zipcode" id="zipcode" type="text" class="formbox" <?php if (isset($missing)) { echo 'value="'.htmlentities($_POST['zipcode']).'"';} ?>/></td> </tr> <tr> <td height="35"><label for="country">Country:</label></td> <td> <input name="country" id="country" type="text" class="formbox" <?php if (isset($missing)) { echo 'value="'.htmlentities($_POST['country']).'"';} ?>/></td> <td><label for="phone">Phone:</label></td> <td><input name="phone" id="phone" type="text" class="formbox" <?php if (isset($missing)) { echo 'value="'.htmlentities($_POST['phone']).'"';} ?>/></td> </tr> <tr> <td height="35"><label for="cellphone">Cell Phone:</label></td> <td><input name="cellphone" id="cellphone" type="text" class="formbox"<?php if (isset($missing)) { echo 'value="'.htmlentities($_POST['cellphone']).'"';} ?> /></td> <td><label for="fax">Fax Number:</label></td> <td><input name="fax" id="fax" type="text" class="formbox" <?php if (isset($missing)) { echo 'value="'.htmlentities($_POST['fax']).'"';} ?>/></td> </tr> <tr> <td height="35"><label for="password">Choose Password:</label></td> <td><input name="password" id="password" type="password" class="formbox" <?php if (isset($missing)) { echo 'value="'.htmlentities($_POST['password']).'"';} ?>/> </td> <td><input type="hidden" name="status" value="1"></td> <td> </td> </tr> </table> <table> <tr> <td colspan="2" valign="top" class="subheader"> </td> <td valign="top"> </td> </tr> <tr> <td colspan="2" valign="top" class="subheader">Additional Info Requested:</td> <td valign="top"> </td> </tr> <tr> <td width="198" valign="top"><div> <p> <input type="checkbox" name="interests[]" value="NLP Practitioner Program" id="NLPPrac" <?php $OK = isset($_POST['interests']) ? true : false; if ($OK && isset($missing) && in_array('NLPPractitionerProgram', $_POST['interests'])) { ?> checked="checked" <?php } ?> /> <label for="anime">NLP Practitioner Program</label> </p> <p> <input type="checkbox" name="interests[]" value="Hypnosis & NLP Intensive" id="HYPnos" <?php $OK = isset($_POST['interests']) ? true : false; if ($OK && isset($missing) && in_array('Hypnosis & NLP Intensive', $_POST['interests'])) { ?> checked="checked" <?php } ?> /> <label for="Hypnosis">Hypnosis & NLP Intensive</label> </p> <p> <input type="checkbox" name="interests[]" value="NLP ChangeMastery" id="NLPChange" <?php $OK = isset($_POST['interests']) ? true : false; if ($OK && isset($missing) && in_array('NLP ChangeMastery', $_POST['interests'])) { ?> checked="checked" <?php } ?> /> <label for="Hypnosis">NLP ChangeMastery ™</label> </p> <p> <input type="checkbox" name="interests[]" value="Meta-Programs Mastery" id="MetaChange" <?php $OK = isset($_POST['interests']) ? true : false; if ($OK && isset($missing) && in_array('Meta Programs Mastery', $_POST['interests'])) { ?> checked="checked" <?php } ?> /> <label for="Hypnosis">Meta-Programs Mastery™</label> </p> <p> <input type="checkbox" name="interests[]" value="Conversational Trance" id="ConvTrance" <?php $OK = isset($_POST['interests']) ? true : false; if ($OK && isset($missing) && in_array('Conversational Trance', $_POST['interests'])) { ?> checked="checked" <?php } ?> /> <label for="Hypnosis">Conversational Trance™</label> </p> </td> <td width="207" valign="top"><div> <p> <input type="checkbox" name="interests[]" value="Conversational NLP" id="ConvNLP" <?php $OK = isset($_POST['interests']) ? true : false; if ($OK && isset($missing) && in_array('ConversationalNLP', $_POST['interests'])) { ?> checked="checked" <?php } ?> /> <label for="Conversational NLP">Conversational NLP™</label> </p> <p> <input type="checkbox" name="interests[]" value="Identity Compass Training" id="IdentityCompass" <?php $OK = isset($_POST['interests']) ? true : false; if ($OK && isset($missing) && in_array('Identity Compass Training', $_POST['interests'])) { ?> checked="checked" <?php } ?> /> <label for="Hypnosis">Identity Compass® Training</label> </p> <p> <input type="checkbox" name="interests[]" value="Trance-Forming Identity" id="Trance" <?php $OK = isset($_POST['interests']) ? true : false; if ($OK && isset($missing) && in_array('Trance Forming Identity', $_POST['interests'])) { ?> checked="checked" <?php } ?> /> <label for="Hypnosis">Trance-Forming Identity ™ </label> </p> <p> <input type="checkbox" name="interests[]" value="Identity-Coaching" id="Identity" <?php $OK = isset($_POST['interests']) ? true : false; if ($OK && isset($missing) && in_array('IdentityCoaching', $_POST['interests'])) { ?> checked="checked" <?php } ?> /> <label for="Hypnosis">Identity-Coaching ™ </label> </p> <p> <input type="checkbox" name="interests[]" value="IMNLP & Hypnosis Membership" id="IMHypMem" <?php $OK = isset($_POST['interests']) ? true : false; if ($OK && isset($missing) && in_array('IMNLPHypnosisMembership', $_POST['interests'])) { ?> checked="checked" <?php } ?> /> <label for="Hypnosis">IMNLP & Hypnosis Membership</label> </p> </td> <td width="209" valign="top"><div> <p> <input type="checkbox" name="interests[]" value="ETC WebEx Online Courses" id="ETCWebEx" <?php $OK = isset($_POST['interests']) ? true : false; if ($OK && isset($missing) && in_array('ETC WebEx Online Courses', $_POST['interests'])) { ?> checked="checked" <?php } ?> /> <label for="anime">ETC™ WebEx Online Courses</label> </p> <p> <input type="checkbox" name="interests[]" value="NLP Master Practitioner Program" id="NLPPrac" <?php $OK = isset($_POST['interests']) ? true : false; if ($OK && isset($missing) && in_array('NLP Master Practitioner Program', $_POST['interests'])) { ?> checked="checked" <?php } ?> /> <label for="Hypnosis">NLP Master Practitioner Program</label> </p> <p> <input type="checkbox" name="interests[]" value="NLP In Hypnosis Immersion" id="NLPHyp" <?php $OK = isset($_POST['interests']) ? true : false; if ($OK && isset($missing) && in_array('NLP In Hypnosis Immersion', $_POST['interests'])) { ?> checked="checked" <?php } ?> /> <label for="Hypnosis">NLP In Hypnosis Immersion</label> </p> <p> <input type="checkbox" name="interests[]" value="ExecuSkills" id="ExecSkill" <?php $OK = isset($_POST['interests']) ? true : false; if ($OK && isset($missing) && in_array('ExecuSkills', $_POST['interests'])) { ?> checked="checked" <?php } ?> /> <label for="Hypnosis">ExecuSkills™</label> </p> </td> </tr> </table> <p> <input name="send" id="send" type="submit" value="Send message" /> </p> </form> Quote Link to comment https://forums.phpfreaks.com/topic/121148-form-not-sending-email/ Share on other sites More sharing options...
mallen Posted August 25, 2008 Author Share Posted August 25, 2008 Just as I thought the script works fine. It always has. Something was not right on the clients server. Now my client's host is telling him "In the php script I should add and stipulate a “from line” or a referrer so that it doesn’t default to www user." Why would I need this? It always worked and it just stopped working. It works fine on other servers or hosts Quote Link to comment https://forums.phpfreaks.com/topic/121148-form-not-sending-email/#findComment-625491 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.