TimKukulka Posted February 2, 2014 Share Posted February 2, 2014 Hello, I am writing an app and I am trying to include a feedback form. I have the form and php script written but it isn't working. Can somebody take a look at it and see if I am missing something? This is my first try at writing PHP. The form will submit via email and have five sections: name, email, city, what and comments. Submit to List Name: Email: City: What: Comments: The form shows up fine but it is the PHP I'm having trouble with. Below is the code I have so far for the HTML form and PHP file. I would like an email of the form to go to tim@akluk.com and another screen to pop up that says "Thank You" with a close button to take the viewer back to the home page. I appreciate any help I can get on getting this form to work. I am currently using Dreamweaver as my editor and I modified some code I found here: http://www.freecontactform.com/email_form.php. I am also referencing an O'Reilly book called Learning PHP, MySQL, JavaScript, & CSS. Thanks for your help! submit.htmlsubmit.php // Form HTML // "submit.html" <!DOCTYPE HTML> <html> <head> <meta charset="UTF-8"> <title>Submit to List</title> <meta name="viewport" content="width=device-width,user-scalable=no"> <link rel="stylesheet" href="jquery.mobile-1.0.css" /> <link href="jQueryAssets/jquery.ui.core.min.css" rel="stylesheet" type="text/css"> <link href="jQueryAssets/jquery.ui.theme.min.css" rel="stylesheet" type="text/css"> <link href="jQueryAssets/jquery.ui.button.min.css" rel="stylesheet" type="text/css"> <script src="jquery.js"></script> <script src="script.js"></script> <script src="jquery.mobile-1.0.js"></script> <script src="jQueryAssets/jquery-1.8.3.min.js" type="text/javascript"></script> <script src="jQueryAssets/jquery-ui-1.9.2.button.custom.min.js" type="text/javascript"></script> </head> <body> <div data-role="dialog"> <div data-role="header"> <h1>Submit to List</h1> </div> <div data-role="content"> <form action="submit.php" method="post" data-transition="none"> <div data-role="fieldcontain"> <label for="name">Name:</label> <input type="text" name="name" id="name" value="" required /> </div> <div data-role="fieldcontain"> <label for="email">Email:</label> <input type="email" name="email" id="email" value="" required /> </div> <div data-role="fieldcontain"> <label for="City">City:</label> <input type="text" name="city" id="city" value="" required /> </div> <div data-role="fieldcontain"> <label for="what">What:</label> <input type="text" name="what" id="what" value="" required /> </div> <div data-role="fieldcontain"> <label for="comments">Comments:</label> <textarea cols="40" rows="8" name="comments" id="comments"></textarea> </div> <input type="submit" value="Send" data-theme="a"> </form> </div> </div> </body> </html> // PHP Code // "submit.php" <!DOCTYPE HTML> <html> <head> <meta charset="UTF-8"> <title>Submission</title> <meta name="viewport" content="width=device-width,user-scalable=no"> <link rel="stylesheet" href="jquery.mobile-1.0.css" /> <script src="jquery.js"></script> <script src="script.js"></script> <script src="jquery.mobile-1.0.js"></script> </head> <body> <div data-role="dialog"> <div data-role="header"> <h1>Submit to List</h1> </div> <div data-role="content"> <?php if(isset($_POST['email'])) { // EDIT THE 2 LINES BELOW AS REQUIRED $email_to = "tim@akluk.com"; $email_subject = "List Suggestion"; function died($error) { // your error code can go here echo "We are very sorry, but there were error(s) found with the form you submitted. "; echo "These errors appear below.<br /><br />"; echo $error."<br /><br />"; echo "Please go back and fix these errors.<br /><br />"; die(); } // validation expected data exists if(!isset($_POST['name']) || !isset($_POST['email']) || !isset($_POST['city']) || !isset($_POST['what']) || !isset($_POST['comments'])) { died('We are sorry, but there appears to be a problem with the form you submitted.'); } $name = $_POST['name']; // required $email_from = $_POST['email']; // required $city = $_POST['city']; // required $what = $_POST['what']; // 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,$name)) { $error_message .= 'The Name you entered does not appear to be valid.<br />'; } $string_exp = "/^[A-Za-z .'-]+$/"; if(!preg_match($string_exp,$city)) { $error_message .= 'The City you entered does not appear to be valid.<br />'; } $string_exp = "/^[A-Za-z .'-]+$/"; if(!preg_match($string_exp,$what)) { $error_message .= 'What 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 .= "Name: ".clean_string($name)."\n"; $email_message .= "Email: ".clean_string($email_from)."\n"; $email_message .= "City: ".clean_string($city)."\n"; $email_message .= "What: ".clean_string($what)."\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); ?> Thanks for your suggestion. <a data-role="button" data-inverse="true" href="index.html">Close</a> </div> </div> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/285875-php-contact-form-not-working-for-an-app-im-writing/ Share on other sites More sharing options...
jcbones Posted February 2, 2014 Share Posted February 2, 2014 I don't see anything that looks out of place. I do note one thing that may keep it from working, and that is the FROM header in the mail function. Reason being (and you will have to check with your host), is that many host will not accept mail to the SMTP server (to be sent), unless the FROM header is an email account residing on the SMTP server.In these cases, I use an address from the site, and include a REPLY TO header with the senders address.Of course, I would also suggest removing error suppression (@) from in front of the mail() function as well. Quote Link to comment https://forums.phpfreaks.com/topic/285875-php-contact-form-not-working-for-an-app-im-writing/#findComment-1467411 Share on other sites More sharing options...
TimKukulka Posted February 2, 2014 Author Share Posted February 2, 2014 Hello, Thank you for the quick response. I've added a domain specific address for the FROM header (tim@akluk.com as $email_to) and I took out the @ symbol before mail but I still seem to be getting errors (lots of script) in the app itself (and just "error" when I test from the server). Any ideas? Attached is the new script if anybody has a moment to take a look at the script with the changes in red. Thank you for taking the time to look and help! Tim submit.htmlsubmit.php // submit.php // <!DOCTYPE HTML> <html> <head> <meta charset="UTF-8"> <title>Submission</title> <meta name="viewport" content="width=device-width,user-scalable=no"> <link rel="stylesheet" href="jquery.mobile-1.0.css" /> <script src="jquery.js"></script> <script src="script.js"></script> <script src="jquery.mobile-1.0.js"></script> </head> <body> <div data-role="dialog"> <div data-role="header"> <h1>Submit to List</h1> </div> <div data-role="content"> <?php if(isset($_POST['email'])) { // EDIT THE 2 LINES BELOW AS REQUIRED $email_to = "tim@akluk.com"; $email_subject = "List Suggestion"; function died($error) { // your error code can go here echo "We are very sorry, but there were error(s) found with the form you submitted. "; echo "These errors appear below.<br /><br />"; echo $error."<br /><br />"; echo "Please go back and fix these errors.<br /><br />"; die(); } // validation expected data exists if(!isset($_POST['name']) || !isset($_POST['email']) || !isset($_POST['city']) || !isset($_POST['what']) || !isset($_POST['comments'])) { died('We are sorry, but there appears to be a problem with the form you submitted.'); } $name = $_POST['name']; // required $email_from = $_POST['email']; // required $city = $_POST['city']; // required $what = $_POST['what']; // 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,$name)) { $error_message .= 'The Name you entered does not appear to be valid.<br />'; } $string_exp = "/^[A-Za-z .'-]+$/"; if(!preg_match($string_exp,$city)) { $error_message .= 'The City you entered does not appear to be valid.<br />'; } $string_exp = "/^[A-Za-z .'-]+$/"; if(!preg_match($string_exp,$what)) { $error_message .= 'What 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 .= "Name: ".clean_string($name)."\n"; $email_message .= "Email: ".clean_string($email_from)."\n"; $email_message .= "City: ".clean_string($city)."\n"; $email_message .= "What: ".clean_string($what)."\n"; $email_message .= "Comments: ".clean_string($comments)."\n"; // create email headers $headers = 'From: '.$email_to."\r\n". 'Reply-To: '.$email_from."\r\n". 'X-Mailer: PHP/' . phpversion(); mail($email_to, $email_subject, $email_message, $headers); ?> Thanks for your suggestion. <a data-role="button" data-inverse="true" href="index.html">Close</a> </div> </div> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/285875-php-contact-form-not-working-for-an-app-im-writing/#findComment-1467416 Share on other sites More sharing options...
jcbones Posted February 2, 2014 Share Posted February 2, 2014 Post the errors.If you put your code in [ code ] ... [ / code ] tags, it will preserve formatting and be easier to read. Quote Link to comment https://forums.phpfreaks.com/topic/285875-php-contact-form-not-working-for-an-app-im-writing/#findComment-1467419 Share on other sites More sharing options...
TimKukulka Posted February 2, 2014 Author Share Posted February 2, 2014 Thanks, here is the error I'm getting: "; echo $error." "; echo "Please go back and fix these errors. "; die(); } // validation expected data exists if(!isset($_POST['name']) || !isset($_POST['email']) || !isset($_POST['city']) || !isset($_POST['what']) || !isset($_POST['comments'])) { died('We are sorry, but there appears to be a problem with the form you submitted.'); } $name = $_POST['name']; // required $email_from = $_POST['email']; // required $city = $_POST['city']; // required $what = $_POST['what']; // 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. '; } $string_exp = "/^[A-Za-z .'-]+$/"; if(!preg_match($string_exp,$name)) { $error_message .= 'The Name you entered does not appear to be valid. '; } $string_exp = "/^[A-Za-z .'-]+$/"; if(!preg_match($string_exp,$city)) { $error_message .= 'The City you entered does not appear to be valid. '; } $string_exp = "/^[A-Za-z .'-]+$/"; if(!preg_match($string_exp,$what)) { $error_message .= 'What you entered does not appear to be valid. '; } if(strlen($comments) < 2) { $error_message .= 'The Comments you entered do not appear to be valid. '; } 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 .= "Name: ".clean_string($name)."\n"; $email_message .= "Email: ".clean_string($email_from)."\n"; $email_message .= "City: ".clean_string($city)."\n"; $email_message .= "What: ".clean_string($what)."\n"; $email_message .= "Comments: ".clean_string($comments)."\n"; // create email headers $headers = 'From: '.$email_to."\r\n". 'Reply-To: '.$email_from."\r\n". 'X-Mailer: PHP/' . phpversion(); mail($email_to, $email_subject, $email_message, $headers); ?> Thanks for your suggestion. Quote Link to comment https://forums.phpfreaks.com/topic/285875-php-contact-form-not-working-for-an-app-im-writing/#findComment-1467422 Share on other sites More sharing options...
TimKukulka Posted February 2, 2014 Author Share Posted February 2, 2014 Here is my code as of now: <!DOCTYPE HTML> <html> <head> <meta charset="UTF-8"> <title>Submission</title> <meta name="viewport" content="width=device-width,user-scalable=no"> <link rel="stylesheet" href="jquery.mobile-1.0.css" /> <script src="jquery.js"></script> <script src="script.js"></script> <script src="jquery.mobile-1.0.js"></script> </head> <body> <div data-role="dialog"> <div data-role="header"> <h1>Submit to List</h1> </div> <div data-role="content"> <?php if(isset($_POST['email'])) { // EDIT THE 2 LINES BELOW AS REQUIRED $email_to = "tim@akluk.com"; $email_subject = "List Suggestion"; function died($error) { // your error code can go here echo "We are very sorry, but there were error(s) found with the form you submitted. "; echo "These errors appear below.<br /><br />"; echo $error."<br /><br />"; echo "Please go back and fix these errors.<br /><br />"; die(); } // validation expected data exists if(!isset($_POST['name']) || !isset($_POST['email']) || !isset($_POST['city']) || !isset($_POST['what']) || !isset($_POST['comments'])) { died('We are sorry, but there appears to be a problem with the form you submitted.'); } $name = $_POST['name']; // required $email_from = $_POST['email']; // required $city = $_POST['city']; // required $what = $_POST['what']; // 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,$name)) { $error_message .= 'The Name you entered does not appear to be valid.<br />'; } $string_exp = "/^[A-Za-z .'-]+$/"; if(!preg_match($string_exp,$city)) { $error_message .= 'The City you entered does not appear to be valid.<br />'; } $string_exp = "/^[A-Za-z .'-]+$/"; if(!preg_match($string_exp,$what)) { $error_message .= 'What 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 .= "Name: ".clean_string($name)."\n"; $email_message .= "Email: ".clean_string($email_from)."\n"; $email_message .= "City: ".clean_string($city)."\n"; $email_message .= "What: ".clean_string($what)."\n"; $email_message .= "Comments: ".clean_string($comments)."\n"; // create email headers $headers = 'From: '.$email_to."\r\n". 'Reply-To: '.$email_from."\r\n". 'X-Mailer: PHP/' . phpversion(); mail($email_to, $email_subject, $email_message, $headers); ?> Thanks for your suggestion. <a data-role="button" data-inverse="true" href="index.html">Close</a> </div> </div> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/285875-php-contact-form-not-working-for-an-app-im-writing/#findComment-1467465 Share on other sites More sharing options...
davidannis Posted February 2, 2014 Share Posted February 2, 2014 It looks to me like you have an extra or missing " in this line echo "These errors appear below.<br /><br />"; but I don't see it in the code that you posted. Is the code cut and pasted from the live, current version? Quote Link to comment https://forums.phpfreaks.com/topic/285875-php-contact-form-not-working-for-an-app-im-writing/#findComment-1467467 Share on other sites More sharing options...
TimKukulka Posted February 3, 2014 Author Share Posted February 3, 2014 Hi, thank you for replying to my post. The current PHP code is below. The error is posted above (the error I'm receiving in the actually app when it pulls the PHP). I don't see where I would be missing a quotation mark, I've highlighted the line that I think you are talking about. The form and php files are below as well. Thank you for troubleshooting my code in advance! submit.htmlsubmit.php <!DOCTYPE HTML> <html> <head> <meta charset="UTF-8"> <title>Submission</title> <meta name="viewport" content="width=device-width,user-scalable=no"> <link rel="stylesheet" href="jquery.mobile-1.0.css" /> <script src="jquery.js"></script> <script src="script.js"></script> <script src="jquery.mobile-1.0.js"></script> </head> <body> <div data-role="dialog"> <div data-role="header"> <h1>Submit to List</h1> </div> <div data-role="content"> <?php if(isset($_POST['email'])) { // EDIT THE 2 LINES BELOW AS REQUIRED $email_to = "tim@akluk.com"; $email_subject = "List Suggestion"; function died($error) { // your error code can go here echo "We are very sorry, but there were error(s) found with the form you submitted. "; echo "These errors appear below.<br /><br />"; echo $error."<br /><br />"; echo "Please go back and fix these errors.<br /><br />"; die(); } // validation expected data exists if(!isset($_POST['name']) || !isset($_POST['email']) || !isset($_POST['city']) || !isset($_POST['what']) || !isset($_POST['comments'])) { died('We are sorry, but there appears to be a problem with the form you submitted.'); } $name = $_POST['name']; // required $email_from = $_POST['email']; // required $city = $_POST['city']; // required $what = $_POST['what']; // 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,$name)) { $error_message .= 'The Name you entered does not appear to be valid.<br />'; } $string_exp = "/^[A-Za-z .'-]+$/"; if(!preg_match($string_exp,$city)) { $error_message .= 'The City you entered does not appear to be valid.<br />'; } $string_exp = "/^[A-Za-z .'-]+$/"; if(!preg_match($string_exp,$what)) { $error_message .= 'What 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 .= "Name: ".clean_string($name)."\n"; $email_message .= "Email: ".clean_string($email_from)."\n"; $email_message .= "City: ".clean_string($city)."\n"; $email_message .= "What: ".clean_string($what)."\n"; $email_message .= "Comments: ".clean_string($comments)."\n"; // create email headers $headers = 'From: '.$email_to."\r\n". 'Reply-To: '.$email_from."\r\n". 'X-Mailer: PHP/' . phpversion(); mail($email_to, $email_subject, $email_message, $headers); ?> Thanks for your suggestion. <a data-role="button" data-inverse="true" href="index.html">Close</a> </div> </div> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/285875-php-contact-form-not-working-for-an-app-im-writing/#findComment-1467483 Share on other sites More sharing options...
jazzman1 Posted February 3, 2014 Share Posted February 3, 2014 I don't see any actual errors returned by PHP. Have you ever turned on the php checking error's reporting in the php.ini confing file? Quote Link to comment https://forums.phpfreaks.com/topic/285875-php-contact-form-not-working-for-an-app-im-writing/#findComment-1467484 Share on other sites More sharing options...
TimKukulka Posted February 3, 2014 Author Share Posted February 3, 2014 I am using Dreamweaver to write the PHP and form in. Where would I find the php.ini config file? Would this be something present on the server? Quote Link to comment https://forums.phpfreaks.com/topic/285875-php-contact-form-not-working-for-an-app-im-writing/#findComment-1467485 Share on other sites More sharing options...
jazzman1 Posted February 3, 2014 Share Posted February 3, 2014 (edited) Paste the following on top of the file which contains all php(server side) logic. I think, it's named submit.php ini_set('display_errors',1); ini_set('display_startup_errors',1); error_reporting(-1); PS: To be able to make some setting/editing in php config file named with crappy extension ".ini" you should have an admin(root) privilege to do this I'm not sure what environment are you using? Edited February 3, 2014 by jazzman1 Quote Link to comment https://forums.phpfreaks.com/topic/285875-php-contact-form-not-working-for-an-app-im-writing/#findComment-1467487 Share on other sites More sharing options...
TimKukulka Posted February 3, 2014 Author Share Posted February 3, 2014 Thank you for your reply. I am using Dreamweaver on a Macbook Air. I use Yahoo for my hosting and I have the app and PHP in a directory called "app". I have put the code you supplied into the submit.php file but I still receive an error in testing (I posted it at 12:19AM). Where would I find the config PHP file on my computer or on the server? Thanks for your assistance. <!DOCTYPE HTML> <html> <head> <meta charset="UTF-8"> <title>Submission</title> <meta name="viewport" content="width=device-width,user-scalable=no"> <link rel="stylesheet" href="jquery.mobile-1.0.css" /> <script src="jquery.js"></script> <script src="script.js"></script> <script src="jquery.mobile-1.0.js"></script> </head> <body> <div data-role="dialog"> <div data-role="header"> <h1>Submit to List</h1> </div> <div data-role="content"> <?php ini_set('display_errors',1); ini_set('display_startup_errors',1); error_reporting(-1); if(isset($_POST['email'])) { // EDIT THE 2 LINES BELOW AS REQUIRED $email_to = "tim@akluk.com"; $email_subject = "List Suggestion"; function died($error) { // your error code can go here echo "We are very sorry, but there were error(s) found with the form you submitted. "; echo "These errors appear below.<br /><br />"; echo $error."<br /><br />"; echo "Please go back and fix these errors.<br /><br />"; die(); } // validation expected data exists if(!isset($_POST['name']) || !isset($_POST['email']) || !isset($_POST['city']) || !isset($_POST['what']) || !isset($_POST['comments'])) { died('We are sorry, but there appears to be a problem with the form you submitted.'); } $name = $_POST['name']; // required $email_from = $_POST['email']; // required $city = $_POST['city']; // required $what = $_POST['what']; // 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,$name)) { $error_message .= 'The Name you entered does not appear to be valid.<br />'; } $string_exp = "/^[A-Za-z .'-]+$/"; if(!preg_match($string_exp,$city)) { $error_message .= 'The City you entered does not appear to be valid.<br />'; } $string_exp = "/^[A-Za-z .'-]+$/"; if(!preg_match($string_exp,$what)) { $error_message .= 'What 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 .= "Name: ".clean_string($name)."\n"; $email_message .= "Email: ".clean_string($email_from)."\n"; $email_message .= "City: ".clean_string($city)."\n"; $email_message .= "What: ".clean_string($what)."\n"; $email_message .= "Comments: ".clean_string($comments)."\n"; // create email headers $headers = 'From: '.$email_to."\r\n". 'Reply-To: '.$email_from."\r\n". 'X-Mailer: PHP/' . phpversion(); mail($email_to, $email_subject, $email_message, $headers); ?> Thanks for your suggestion. <a data-role="button" data-inverse="true" href="index.html">Close</a> </div> </div> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/285875-php-contact-form-not-working-for-an-app-im-writing/#findComment-1467490 Share on other sites More sharing options...
jazzman1 Posted February 3, 2014 Share Posted February 3, 2014 (edited) So just to clarify. You're using Dreamweaver as a default code editor on your apple machine and you want to send emails through out your personal Yahoo account, right? So, if it's true then you're able to make some changes into php config file because the server is located on your own machine and you're the owner. So my further questions are, have you ever started the web (apache) server service and do you have a copy of php version installed on this machine? Edited February 3, 2014 by jazzman1 Quote Link to comment https://forums.phpfreaks.com/topic/285875-php-contact-form-not-working-for-an-app-im-writing/#findComment-1467494 Share on other sites More sharing options...
TimKukulka Posted February 3, 2014 Author Share Posted February 3, 2014 I use Dreamweaver on an Apple and I use Yahoo as my hosting/mail services (I have a domain that I will be receiving mail from). Thank you for helping out! Quote Link to comment https://forums.phpfreaks.com/topic/285875-php-contact-form-not-working-for-an-app-im-writing/#findComment-1467538 Share on other sites More sharing options...
davidannis Posted February 3, 2014 Share Posted February 3, 2014 Do you have php on your Mac? Are you doing this testing on your local machine or on Yahoo's server? When you said Thanks, here is the error I'm getting: I assumed that code was appearing in the browser. If that's not the case, you need to paste the code in post #11 in the top of your script, submit the form on a server, and paste what shows in the browser here. You can't fix errors if you don't know what they are. Quote Link to comment https://forums.phpfreaks.com/topic/285875-php-contact-form-not-working-for-an-app-im-writing/#findComment-1467543 Share on other sites More sharing options...
TimKukulka Posted February 3, 2014 Author Share Posted February 3, 2014 I am testing this on a server and the post was the error I was receiving when it pulled the script from the server on the compiled app (browser). Here it is again: "; echo $error." "; echo "Please go back and fix these errors. "; die(); } // validation expected data exists if(!isset($_POST['name']) || !isset($_POST['email']) || !isset($_POST['city']) || !isset($_POST['what']) || !isset($_POST['comments'])) { died('We are sorry, but there appears to be a problem with the form you submitted.'); } $name = $_POST['name']; // required $email_from = $_POST['email']; // required $city = $_POST['city']; // required $what = $_POST['what']; // 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. '; } $string_exp = "/^[A-Za-z .'-]+$/"; if(!preg_match($string_exp,$name)) { $error_message .= 'The Name you entered does not appear to be valid. '; } $string_exp = "/^[A-Za-z .'-]+$/"; if(!preg_match($string_exp,$city)) { $error_message .= 'The City you entered does not appear to be valid. '; } $string_exp = "/^[A-Za-z .'-]+$/"; if(!preg_match($string_exp,$what)) { $error_message .= 'What you entered does not appear to be valid. '; } if(strlen($comments) < 2) { $error_message .= 'The Comments you entered do not appear to be valid. '; } 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 .= "Name: ".clean_string($name)."\n"; $email_message .= "Email: ".clean_string($email_from)."\n"; $email_message .= "City: ".clean_string($city)."\n"; $email_message .= "What: ".clean_string($what)."\n"; $email_message .= "Comments: ".clean_string($comments)."\n"; // create email headers $headers = 'From: '.$email_to."\r\n". 'Reply-To: '.$email_from."\r\n". 'X-Mailer: PHP/' . phpversion(); mail($email_to, $email_subject, $email_message, $headers); ?> Thanks for your suggestion. Quote Link to comment https://forums.phpfreaks.com/topic/285875-php-contact-form-not-working-for-an-app-im-writing/#findComment-1467546 Share on other sites More sharing options...
jazzman1 Posted February 3, 2014 Share Posted February 3, 2014 I've never knew that Yahoo provides a web hiosting service, it's a something new to me. So, do a simple test for us. Open up Dreamweaver and connect to the yahoo server. Create a file named phpinfo.php inside this app directory (assuming it's a your web server working directory) and copy/paste the following simple php script: phpinfo.php <?php phpinfo(); Try to open this file up with your browser and tell us what result you're getting. jazz. Quote Link to comment https://forums.phpfreaks.com/topic/285875-php-contact-form-not-working-for-an-app-im-writing/#findComment-1467563 Share on other sites More sharing options...
TimKukulka Posted February 3, 2014 Author Share Posted February 3, 2014 Thanks for your response I am currently away from my computer but when I get back I will definitely try it out and post the results. On a side note I have successfully created a mobile contact page in Adobe Muse and I have sent test messages from it on my Yahoo server. Now it is a matter of tieing the form into the app. It would just be different than the form I've been posting about. Quote Link to comment https://forums.phpfreaks.com/topic/285875-php-contact-form-not-working-for-an-app-im-writing/#findComment-1467590 Share on other sites More sharing options...
TimKukulka Posted February 4, 2014 Author Share Posted February 4, 2014 Hello, I've attached the result I get when I opened the document on my server. Thanks for helping me out! Regards, Tim phpinfo().pdf Quote Link to comment https://forums.phpfreaks.com/topic/285875-php-contact-form-not-working-for-an-app-im-writing/#findComment-1467646 Share on other sites More sharing options...
davidannis Posted February 4, 2014 Share Posted February 4, 2014 the "error messages" you get are part of the code on your page. My theory is that Dreamweaver is messing things up causing your code to be output to your browser instead of being executed. Can you try just uploading the script without dreamweaver and see if it works? Quote Link to comment https://forums.phpfreaks.com/topic/285875-php-contact-form-not-working-for-an-app-im-writing/#findComment-1467647 Share on other sites More sharing options...
Solution jazzman1 Posted February 4, 2014 Solution Share Posted February 4, 2014 (edited) Then, you have an actual syntax error. So, my IDE (NetBeans) complains of missing curly brace in submit.php file. Take this instead yours ( see the line 176) submit.php <!DOCTYPE HTML> <html> <head> <meta charset="UTF-8"> <title>Submission</title> <meta name="viewport" content="width=device-width,user-scalable=no"> <link rel="stylesheet" href="jquery.mobile-1.0.css" /> <script src="jquery.js"></script> <script src="script.js"></script> <script src="jquery.mobile-1.0.js"></script> </head> <body> <div data-role="dialog"> <div data-role="header"> <h1>Submit to List</h1> </div> <div data-role="content"> <?php if(isset($_POST['email'])) { // EDIT THE 2 LINES BELOW AS REQUIRED $email_to = "tim@akluk.com"; $email_subject = "List Suggestion"; function died($error) { // your error code can go here echo "We are very sorry, but there were error(s) found with the form you submitted. "; echo "These errors appear below.<br /><br />"; echo $error."<br /><br />"; echo "Please go back and fix these errors.<br /><br />"; die(); } // validation expected data exists if(!isset($_POST['name']) || !isset($_POST['email']) || !isset($_POST['city']) || !isset($_POST['what']) || !isset($_POST['comments'])) { died('We are sorry, but there appears to be a problem with the form you submitted.'); } $name = $_POST['name']; // required $email_from = $_POST['email']; // required $city = $_POST['city']; // required $what = $_POST['what']; // 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,$name)) { $error_message .= 'The Name you entered does not appear to be valid.<br />'; } $string_exp = "/^[A-Za-z .'-]+$/"; if(!preg_match($string_exp,$city)) { $error_message .= 'The City you entered does not appear to be valid.<br />'; } $string_exp = "/^[A-Za-z .'-]+$/"; if(!preg_match($string_exp,$what)) { $error_message .= 'What 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 .= "Name: ".clean_string($name)."\n"; $email_message .= "Email: ".clean_string($email_from)."\n"; $email_message .= "City: ".clean_string($city)."\n"; $email_message .= "What: ".clean_string($what)."\n"; $email_message .= "Comments: ".clean_string($comments)."\n"; // create email headers $headers = 'From: '.$email_to."\r\n". 'Reply-To: '.$email_from."\r\n". 'X-Mailer: PHP/' . phpversion(); mail($email_to, $email_subject, $email_message, $headers); } // missing closing curly brace ?> Thanks for your suggestion. <a data-role="button" data-inverse="true" href="index.html">Close</a> </div> </div> </body> </html> Edited February 4, 2014 by jazzman1 Quote Link to comment https://forums.phpfreaks.com/topic/285875-php-contact-form-not-working-for-an-app-im-writing/#findComment-1467653 Share on other sites More sharing options...
TimKukulka Posted February 6, 2014 Author Share Posted February 6, 2014 Thanks that was the issue. I appreciate your help! Quote Link to comment https://forums.phpfreaks.com/topic/285875-php-contact-form-not-working-for-an-app-im-writing/#findComment-1467903 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.