stiao Posted July 11, 2011 Share Posted July 11, 2011 Hi. I'm currently trying to create a questionnaire for clients using a PHP mailing example I found here: http://www.freecontactform.com/email_form.php I modified it but for some reason the form is not outputting errors and nothing is being sent. Could someone look over it? I'm currently using the same code on my portfolio site and it works fine. mail.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Design Questionnaire</title> <style type="text/css"> body { font-family:Verdana, Geneva, sans-serif; font-size:11px; background:#f4f3f0; } a:link {color: #555; text-decoration: underline; } a:active {color: #555; text-decoration: underline; } a:visited {color: #555; text-decoration: underline; } a:hover {color: #888; text-decoration: none; } #container { width: 60%; max-width:600px; margin: 100px auto; padding: 0px; background-color: #fff; color:#555; border-top: 4px solid #d5d5d5; border-bottom: 4px solid #d5d5d5; line-height: 140%; padding:60px 40px 20px 40px; } #container h1 { padding:0; margin:0; } #container h2 { padding:0 0 5px 0; margin:0 0 0 0; } #intro { padding:0; margin:0; width:70%; } .section { background-color:#f4f3f0; padding:10px; margin:5px 0 15px 0; } #title { float: left; width: 400px; margin: 0; padding: 0; } .question { padding: 5px 5px 5px 10px; border:0 0 1px 0 #000 thin; background-color:#edebe6; width:70%; } .response { padding: 5px 5px 5px 5px; border-style: solid; background-color:#edebe6; width:30%; } #invoice { float: right; width: 160px; margin: 0; padding: 13px 0 0 0; vertical-align:text-bottom; text-align:right; font-size:14px; } #content{ clear: both; margin: 0; padding: 5px 0 0 0; } #footer { padding-top:10px; font-size:9px; } </style> </head> <body> <div id="container"> <div id="title"> <h1>Design Questionnaire </h1> </div> <div id="content"> <div id="intro"> <p>Thank you for choosing tiao.ca for your graphic design project. Please fill out the form below to the best of your ability. If there are any questions you do not understand, feel free to contact me.</p> <p>This questionnaire asks a few standard questions that will allow me a better understanding of your brand, which will reflect in the design.</p> <p>You can trust that all your information will be kept confidential and not shared with any third-party.</p> </div> <form name="contactform" method="post" action="submitform.php"> <div class="section"> <table> <tr> <td valign="top" colspan="2"> <h2>GENERAL INFORMATION</h2> </td> </tr> <tr> <td class="question" valign="top"> <label for="contact_name">Contact Name *</label> </td> <td class="response" valign="top"> <input type="text" name="contact_name" maxlength="50" size="30"> </td> </tr> <tr> <td class="question" valign="top"> <label for="company_name">Company Name *</label> </td> <td class="response" valign="top"> <input type="text" name="company_name" maxlength="50" size="30"> </td> </tr> <tr> <td class="question" valign="top"> <label for="email_address">Email Address *</label> </td> <td class="response" valign="top"> <input type="text" name="email_address" maxlength="50" size="30"> </td> </tr> <tr> <td class="question" valign="top"> <label for="day_telephone">Day Telephone *</label> </td> <td class="response" valign="top"> <input type="text" name="day_telephone" maxlength="50" size="30"> </td> </tr> <tr> <td class="question" valign="top"> <label for="evening_phone">Evening Phone</label> </td> <td class="response" valign="top"> <input type="text" name="evening_phone" maxlength="50" size="30"> </td> </tr> <tr> <td class="question" valign="top"> <label for="preferred_contact_method">Preferred Contact Method</label> </td> <td class="response" valign="top"> <input type="radio" name="preferred_contact_method" value="yes"> Email<br> <input type="radio" name="preferred_contact_method" value="no"> Phone<br> </td> </tr> <tr> <td class="question" valign="top"> <label for="address">Address *</label> </td> <td class="response" valign="top"> <input type="text" name="address" maxlength="50" size="30"> </td> </tr> <tr> <td class="question" valign="top"> <label for="mailing_list">Would you like our join the mailing list?</label> </td> <td class="response" valign="top"> <input type="radio" name="mailing_list" value="yes"> Yes<br> <input type="radio" name="mailing_list" value="no"> No Thanks<br> </td> </tr> </table> </div> <div class="section"> <table> <tr> <td valign="top" colspan="2"> <h2>PROJECT</h2> </td> </tr> <tr> <td class="question" valign="top"> <label for="services">What services are you interested in?</label> </td> <td class="response" valign="top"> <input type="checkbox" name="services" value="branding"> Branding<br> <input type="checkbox" name="services" value="Illustration"> Illustration<br> <input type="checkbox" name="services" value="webdesign"> Web Design<br> </td> </tr> <tr> <td class="question" valign="top"> <label for="three_adjectives">Name 3 adjectives that describe your service and/or product</label> </td> <td class="response" valign="top"> <input type="text" name="3_adjectives" maxlength="50" size="30"> </td> </tr> <tr> <td class="question" valign="top"> <label for="long_term_goals">What are the long term goals of your company?</label> </td> <td class="response" valign="top"> <input type="text" name="long_term_goals" maxlength="50" size="30"> </td> </tr> <tr> <td class="question" valign="top"> <label for="benchmarking">Who are your main competitors</label> </td> <td class="response" valign="top"> <input type="text" name="competitors" maxlength="50" size="30"> </td> </tr> <tr> <td class="question" valign="top"> <label for="competitors_differ">How do you differ from your competitors?</label> </td> <td class="response" valign="top"> <input type="text" name="competitors_differ" maxlength="50" size="30"> </td> </tr> </table> </div> <div class="section"> <table> <tr> <td valign="top" colspan="2"> <h2>BRAND</h2> </td> </tr> <tr> <td class="question" valign="top"> <label for="target_age">What is the age range of your target customer base?</label> </td> <td class="response" valign="top"> <input type="text" name="target_age" maxlength="50" size="30"> </td> </tr> <tr> <td class="question" valign="top"> <label for="specific_imagery">Do you have any specific imagery in mind for your logo?</label> </td> <td class="response" valign="top"> <input type="text" name="specific_imagery" maxlength="50" size="30"> </td> </tr> <tr> <td class="question" valign="top"> <label for="colour_preference"> Do you have any colour preferences, or existing brand colour</label> </td> <td class="response" valign="top"> <input type="text" name="colour_preference" maxlength="50" size="30"> </td> </tr> <tr> <td class="question" valign="top"> <label for="colour_oppose">Do you have any colours that you do not wish to use?</label> </td> <td class="response" valign="top"> <input type="text" name="colour_oppose" maxlength="50" size="30"> </td> </tr> <tr> <td class="question" valign="top"> <label for="message_convey">What feeling or message do you want your logo to convey?</label> </td> <td class="response" valign="top"> <input type="text" name="message_convey" maxlength="50" size="30"> </td> </tr> <tr> <td class="question" valign="top"> <label for="name_worded">How do you prefer your logo to be worded or written out?</label> </td> <td class="response" valign="top"> <input type="text" name="name_worded" maxlength="50" size="30"> </td> </tr> <tr> <td class="question" valign="top"> <label for="logo_usuage"> Where will you logo be use?</label> </td> <td class="response" valign="top"> <input type="text" name="logo_usuage" maxlength="50" size="30"> </td> </tr> </table> </div> <div class="section"> <table> <tr> <td valign="top" colspan="2"> <h2>D. Web Design</h2> </td> </tr> <tr> <td class="question" valign="top"> <label for="navigations">What are the navigation menus you intend to have?</label> </td> <td class="response" valign="top"> <input type="text" name="navigations" maxlength="50" size="30"> </td> </tr> <tr> <td class="question" valign="top"> <label for="submenus">What submenu items do you intend to have?</label> </td> <td class="response" valign="top"> <input type="text" name="submenus" maxlength="50" size="30"> </td> </tr> <tr> <td class="question" valign="top"> <label for="additional_submenus">Are there additional levels of sub-menus items you intend to have?</label> </td> <td class="response" valign="top"> <input type="text" name="additional_submenus" maxlength="50" size="30"> </td> </tr> <tr> <td class="question" valign="top"> <label for="favourite_sites">List some websites that you admire and what you like about them.</label> </td> <td class="response" valign="top"> <textarea rows="8" cols="22" name="favourite_sites"> </textarea> </td> </tr> <tr> <td class="question" valign="top"> <label for="advertising">Does your site require space for advertising?</label> </td> <td class="response" valign="top"> <input type="radio" name="advertising" value="yes"> Yes<br> <input type="radio" name="advertising" value="no"> No<br> </td> </tr> <tr> <td class="question" valign="top"> <label for="advertisement_dimensions">What are the dimensions of advertisements?</label> </td> <td class="response" valign="top"> <input type="text" name="advertisement_dimensions" maxlength="50" size="30"> </td> </tr> <tr> <td class="question" valign="top"> <label for="content_finalized">Is the content for your site finalized?</label> </td> <td class="response" valign="top"> <input type="radio" name="content_finalized" value="yes"> Yes<br> <input type="radio" name="content_finalized" value="no"> No<br> </td> </tr> <tr> <td class="question" valign="top"> <label for="content_finalized_date">If no to the previous question, when will it be ready?</label> </td> <td class="response" valign="top"> <input type="text" name="content_finalized_date" maxlength="50" size="30"> </td> </tr> <tr> <td class="question" valign="top"> <label for="domains_and_hosting">Will you require domain registration and web hosting services?</label> </td> <td class="response" valign="top"> <input type="checkbox" name="services" value="domains_and_hosting"> Domain Registration<br> <input type="checkbox" name="services" value="domains_and_hosting"> Web Hosting<br> </td> </tr> </table> </div> <div class="section"> <table> <tr> <td valign="top" colspan="2"> <h2>E. Forecasts</h2> </td> </tr> <tr> <td class="question" valign="top"> <label for="budget">What is the estimated budget for the production of this project?</label> </td> <td class="response" valign="top"> <input type="text" name="budget" maxlength="50" size="30"> </td> </tr> <tr> <td class="question" valign="top"> <label for="deadline">What is your preferred or expected deadline?</label> </td> <td class="response" valign="top"> <input type="text" name="deadline" maxlength="50" size="30"> </td> </tr> </table> </div> <div class="section"> <table> <tr> <td valign="top" colspan="2"> <h2>F. Additional Questions</h2> </td> </tr> <tr> <td class="question" valign="top"> <label for="comments">Is there anything we missed that should be noted?</label> </td> <td class="response" valign="top"> <textarea rows="8" cols="22 wrap="physical" name="comments"> </textarea> </td> </tr> </table> </div> <tr> <td align=""> </td> <td align="right"> <input type="submit" value="Submit Questionnaire"> </td> </tr> </form> </table> </div> </body> </html> submitform.php <div class="clearboth"></div> <div id="etc"> <br /> <br /> </div> <div id="description"> <br /> <br /> <p><strong><u>Contact Me</u></strong><br> <?php if(isset($_POST['email'])) { // EDIT THE 2 LINES BELOW AS REQUIRED $email_to = "addresshere"; $email_subject = "Contact"; function died($error) { // your error code can go here echo "Sorry, but it seems there were some errors. "; echo "These errors appear below.<br /><br />"; echo $error."<br /><br />"; echo "You can go back and try again.<br /><br />"; die(); } // validation expected data exists if(!isset($_POST['contact_name']) || !isset($_POST['company_name']) || !isset($_POST['email_address']) || !isset($_POST['day_telephone']) || !isset($_POST['evening_telephone']) || !isset($_POST['preferred_contact_method']) || !isset($_POST['address']) || !isset($_POST['mailing_list']) || !isset($_POST['services']) || !isset($_POST['three_adjectives']) || !isset($_POST['long_term_goals']) || !isset($_POST['benchmarking']) || !isset($_POST['competitors_differ']) || !isset($_POST['target_age']) || !isset($_POST['specific_imagery']) || !isset($_POST['colour_preference']) || !isset($_POST['colour_oppose']) || !isset($_POST['message_convey']) || !isset($_POST['name_worded']) || !isset($_POST['logo_usage']) || !isset($_POST['navigations']) || !isset($_POST['submenus']) || !isset($_POST['additional_submenus']) || !isset($_POST['favourite_sites']) || !isset($_POST['advertising']) || !isset($_POST['advertisement_dimensions']) || !isset($_POST['content_finalized']) || !isset($_POST['content_finalized_date']) || !isset($_POST['domains_and_hosting']) || !isset($_POST['budget']) || !isset($_POST['deadline']) || !isset($_POST['comments'])) { died('We are sorry, but there appears to be a problem with the form you submitted.'); } $contact_name = $_POST['contact_name']; // required $company_name = $_POST['company_name']; // required $email_from = $_POST['email_address']; // required $day_telephone = $_POST['day_telephone']; // not required $evening_telephone = $_POST['evening_telephone']; // not required $preferred_contact_method = $_POST['preferred_contact_method']; // not required $address = $_POST['address']; // not required $mailing_list = $_POST['mailing_list']; // not required $services = $_POST['services']; // not required $three_adjectives = $_POST['3_adjectives']; // not required $long_term_goals = $_POST['long_term_goals']; // not required $benchmarking = $_POST['benchmarking']; // not required $competitors_differ = $_POST['competitors_differ']; // not required $target_age = $_POST['target_age']; // not required $specific_imagery = $_POST['specific_imagery']; // not required $colour_preference = $_POST['colour_preference']; // not required $colour_oppose = $_POST['colour_oppose']; // not required $message_convey = $_POST['message_convey']; // not required $name_worded = $_POST['name_worded']; // not required $logo_usage = $_POST['logo_usage']; // not required $navigations = $_POST['navigations']; // not required $submenus = $_POST['submenus']; // not required $additional_submenus = $_POST['additional_submenus']; // not required $favourite_sites = $_POST['favourite_sites']; // not required $advertising = $_POST['advertising']; // not required $advertisement_dimensions = $_POST['advertisement_dimensions']; // not required $content_finalized = $_POST['content_finalized']; // not required $content_finalized_date = $_POST['content_finalized_date']; // not required $domains_and_hosting = $_POST['domains_and_hosting']; // not required $budget = $_POST['budget']; // not required $deadline = $_POST['deadline']; // not required $comments = $_POST['comments']; // required $error_message = ""; $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/'; if(!preg_match($email_exp,$email_from)) { $error_message .= 'The Email Address you entered does not appear to be valid.<br />'; } $string_exp = "/^[A-Za-z .'-]+$/"; if(!preg_match($string_exp,$contact_name)) { $error_message .= 'The First Name you entered does not appear to be valid.<br />'; } if(!preg_match($string_exp,$company_name)) { $error_message .= 'The Last Name you entered does not appear to be valid.<br />'; } if(strlen($comments) < 2) { $error_message .= 'The Comments you entered do not appear to be valid.<br />'; } if(strlen($error_message) > 0) { died($error_message); } $email_message = "Form details below.\n\n"; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $email_message .= "First Name: ".clean_string($contact_name)."\n"; $email_message .= "Last Name: ".clean_string($company_name)."\n"; $email_message .= "Email: ".clean_string($email_from)."\n"; $email_message .= "Day Telephone: ".clean_string($day_telephone)."\n"; $email_message .= "Evening Telephone: ".clean_string($evening_telephone)."\n"; $email_message .= "Preferred Contact Method: ".clean_string($preferred_contact_method)."\n"; $email_message .= "Day Telephone: ".clean_string($address)."\n"; $email_message .= "Day Telephone: ".clean_string($mailing_list)."\n"; $email_message .= "Day Telephone: ".clean_string($services)."\n"; $email_message .= "Day Telephone: ".clean_string($three_adjectives)."\n"; $email_message .= "Day Telephone: ".clean_string($long_term_goals)."\n"; $email_message .= "Day Telephone: ".clean_string($benchmarking)."\n"; $email_message .= "Day Telephone: ".clean_string($competitors_differ)."\n"; $email_message .= "Day Telephone: ".clean_string($target_age)."\n"; $email_message .= "Day Telephone: ".clean_string($specific_imagery)."\n"; $email_message .= "Day Telephone: ".clean_string($colour_preference)."\n"; $email_message .= "Day Telephone: ".clean_string($colour_oppose)."\n"; $email_message .= "Day Telephone: ".clean_string($message_convey)."\n"; $email_message .= "Day Telephone: ".clean_string($name_worded)."\n"; $email_message .= "Day Telephone: ".clean_string($logo_usage)."\n"; $email_message .= "Day Telephone: ".clean_string($navigations)."\n"; $email_message .= "Day Telephone: ".clean_string($submenus)."\n"; $email_message .= "Day Telephone: ".clean_string($additional_submenus)."\n"; $email_message .= "Day Telephone: ".clean_string($favourite_sites)."\n"; $email_message .= "Day Telephone: ".clean_string($advertising)."\n"; $email_message .= "Day Telephone: ".clean_string($advertisement_dimensions)."\n"; $email_message .= "Day Telephone: ".clean_string($content_finalized)."\n"; $email_message .= "Day Telephone: ".clean_string($content_finalized_date)."\n"; $email_message .= "Day Telephone: ".clean_string($domains_and_hosting)."\n"; $email_message .= "Day Telephone: ".clean_string($budget)."\n"; $email_message .= "Day Telephone: ".clean_string($deadline)."\n"; $email_message .= "Comments: ".clean_string($comments)."\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 --> <?php } ?> Thanks for contacting me! You message was sent. You can expect a response in 2-3 days. </p> Would appreciate any help! Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/241644-php-mail-form-problem/ Share on other sites More sharing options...
stiao Posted July 11, 2011 Author Share Posted July 11, 2011 mm. Not really sure why it worked but I removed all the entries under "// validation expected data exists" and it's working now. Thanks for those who read into this! Quote Link to comment https://forums.phpfreaks.com/topic/241644-php-mail-form-problem/#findComment-1241136 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.