Not working so simple for some reason, its driving me mad. I have missed out the check boxes on purpous for now just want to get the rest working then was gonna worry about sorting the checkboxs, but it just wont work at all for some reason.. But if someone could help me out with this that would be awsome. Form code <form name="enquiryform" method="post" action="process_enquiry.php"> <fieldset> <legend>Fleet Management Enquiry</legend> <p><label for="name">Name</label> <input type="text" id="name" /></p> <p><label for="company">Company</label> <input type="text" id="company" /><br /></p> <p><label for="email">E-mail</label> <input type="text" id="email" /><br /></p> <p><label for="phone">Phone Number</label> <input type="text" id="phone" /><br /></p> <p><label for="fleet_size">Fleet Size</label> <input type="text" id="fleet_size" /><br /></p> <p id="inter">Services Interested In:</p> <p><label id="services">Accident Managment</label><input type="checkbox" name="services" value="accident-management" /></p> <p><label id="services">Duty of Care</label><input type="checkbox" name="services" value="duty-of-care" /></p> <p><label id="services">Fleet Policies</label><input type="checkbox" name="services" value="fleet-policies" /></p> <p><label id="services">GAP Insurance</label><input type="checkbox" name="services" value="gap-insurance" /></p> <p><label id="services">Vehicle Funding</label><input type="checkbox" name="services" value="vehicle-funding" /></p> <p><label id="services">Vehicle Insurance</label><input type="checkbox" name="services" value="vehicle-insurance" /></p> <p><label id="services">Vehicle Maintenance</label><input type="checkbox" name="services" value="vehicle-maintenance" /></p> <p class="submit"><input type="submit" value="Submit" /></p> </fieldset> </form> PHP: process_enquiry.php <?php if(isset($_POST['email'])) { // EDIT THE 2 LINES BELOW AS REQUIRED $email_to = "been@replaced.co.uk"; $email_subject = "Emails subject been replaced"; function died($error) { // your error code can go here echo "<br /><p>We are very sorry, but there were errors found with the form you submitted. "; echo "These errors appear below.</p>"; echo "<p> ".$error."</p>"; echo "<p>Please go back and fix these errors.</p>"; echo "<p><a href='#' onClick='history.go(-1)'><img src='img/green-arrow.png' alt='Green Back Arrow' /></a></p>"; die(); } // validation expected data exists if(!isset($_POST['name']) || !isset($_POST['company']) || !isset($_POST['email']) || !isset($_POST['phone']) || !isset($_POST['fleet_size'])) { died('We are sorry, but there appears to be a problem with the form your submitted.'); } $name = $_POST['name']; // required $company = $_POST['company']; // not required $email = $_POST['email']; // required $phone = $_POST['phone']; // required $fleet_size = $_POST['fleet_size']; // required $error_message = "This has failed validation"; $string_exp = "^[a-z .'-]+$"; if(!eregi($string_exp,$name)) { $error_message .= '* The Name you entered does not appear to be valid.<br />'; } $phone = ereg_replace('[^0-9]', '', $_POST['phone']); if (!filter_var($phone, FILTER_VALIDATE_REGEXP, array('options' => array('regexp' => "/^0[1-9][0-9]{8,9}$/")))) { $error_message .= '* The phone number you entered does not appear to be valid.<br />'; } $mobile = ereg_replace('[^0-9]', '', $_POST['mobile']); if (!filter_var($mobile, FILTER_VALIDATE_REGEXP, array('options' => array('regexp' => "/^0[1-9][0-9]{8,9}$/")))) { $error_message .= '* The mobile number you entered does not appear to be valid.<br />'; } $email_exp = "^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$"; if(!eregi($email_exp,$email_from)) { $error_message .= '* The Email Address you entered does not appear to be valid.<br />'; } if(strlen($error_message) > 0) { died($error_message); } $email_message = "Contact Details.\n\n"; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $email_message .= "Name: ".clean_string($name)."\n"; $email_message .= "Company Name: ".clean_string($company)."\n"; $email_message .= "Email: ".clean_string($email)."\n"; $email_message .= "Telephone: ".clean_string($phone)."\n"; $email_message .= "Date Required: ".clean_string($fleet_size)."\n"; // create email headers $headers = 'From: '.$email_from."\r\n". 'Reply-To: '.$email_from."\r\n" . 'X-Mailer: PHP/' . phpversion(); @mail($email_to, $email_subject, $email_message, $headers); ?> <!-- include your own success html here --> <p> </p> <h2>Thank you for contacting us for your quote.<br /> We will be in touch with you very soon.</h2> <? } ?> PHP:
you definitely have a whole lot going on in there. Try the standard email script from below and then make sure that works and build up your script from there to your desired version <?php $to = 'nobody@example.com'; $subject = 'the subject'; $message = 'hello'; $headers = 'From: ' . "\r\n" . 'Reply-To: ' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail($to, $subject, $message, $headers); ?>
Erm thanks but not sure how that helps me fix my current script at all :/ I have had this same script working an various other forms just obviously messed something up somewhere and carnt see where.
Before "@mail" statement, put some echo statements to print $email_to, $email_subject, $email_message & $headers. Then you will be able to findout the issue.
i know its not ideal but breaking the script down and testing the most basic function and then adding to the script is how i usually approach a problem like this. You can just test the mail function in its most basic sense and then add the rest of the script afterwords <?php if(isset($_POST['email'])) { // EDIT THE 2 LINES BELOW AS REQUIRED $email_to = "been@replaced.co.uk"; $email_subject = "Emails subject been replaced"; $name = $_POST['name']; // required $company = $_POST['company']; // not required $email = $_POST['email']; // required $phone = $_POST['phone']; // required $fleet_size = $_POST['fleet_size']; // required $email_message = "Contact Details.\n\n"; $email_message .= "Name: ".clean_string($name)."\n"; $email_message .= "Company Name: ".clean_string($company)."\n"; $email_message .= "Email: ".clean_string($email)."\n"; $email_message .= "Telephone: ".clean_string($phone)."\n"; $email_message .= "Date Required: ".clean_string($fleet_size)."\n"; // create email headers $headers = 'From: '.$email_from."\r\n". 'Reply-To: '.$email_from."\r\n" . 'X-Mailer: PHP/' . phpversion(); @mail($email_to, $email_subject, $email_message, $headers); } ?> Code (markup): <!-- include your own success html here --> <p> </p> <h2>Thank you for contacting us for your quote.<br /> We will be in touch with you very soon.</h2>
Ah managed to fix it in the end was not the scripts fault exactly, it was do to the folder structure I have as the site has a template file and the base file just sets title,description and keywords variables, then calls for a template file which the template calls for the content file. And my content file on the enquiry form was not sending the post data to the right location. Sorted now anyway cheers.
Yeah and going back to basics is what made me realise to be fair replaced the process_enquiry.php file with a basic one which just echo the post array, even that would not work so realised must have been an issue with the form action.