Saturday 15 August 2015

html - PHP Email Form Not Submitting -



html - PHP Email Form Not Submitting -

okay, i've looked around specific question wasn't able find it, hope isn't repeat.

so have set contacts form using "/contacts.html" page linked "html_form_send.php" located on local host. 1 time user presses "submit" message comes on next page:

"we sorry, there error(s) found form submitted. these errors appear below.

we sorry, there appears problem form submitted.

please go , prepare these errors."

this message appears whether fill out fields or none of fields, correctly, or incorrectly. why?

<?php if(isset($_post['email'])) { // alter 2 lines below $email_to = "xxxxxxxx.yyyyyyy@gmail.com"; $email_subject = "quantum1connect contact request"; function died($error) { // error code can go here echo "we sorry, there error(s) found form submitted. "; echo "these errors appear below.<br /><br />"; echo $error."<br /><br />"; echo "please go , prepare these errors.<br /><br />"; die(); } // validation expected info exists if(!isset($_post['first_name']) || !isset($_post['last_name']) || !isset($_post['email']) || !isset($_post['telephone']) || !isset($_post['comments'])) { died('we sorry, there appears problem form submitted.'); } $first_name = $_post['first_name']; // required $last_name = $_post['last_name']; // not required $email_from = $_post['email']; // required $telephone = $_post['telephone']; // 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 entered not appear valid.<br />'; } $string_exp = "/^[a-za-z .'-]+$/"; if(!preg_match($string_exp,$first_name)) { $error_message .= 'the first name entered not appear valid.<br />'; } if(!preg_match($string_exp,$last_name)) { $error_message .= 'the lastly name entered not appear valid.<br />'; } if(strlen($comments) < 2) { $error_message .= 'the comments entered not appear 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"); homecoming str_replace($bad,"",$string); } $email_message .= "first name: ".clean_string($first_name)."\n"; $email_message .= "last name: ".clean_string($last_name)."\n"; $email_message .= "email: ".clean_string($email_from)."\n"; $email_message .= "telephone: ".clean_string($telephone)."\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); ?> <!-- place own success html below --> contacting me! respond within 24 hours of receiving message! <?php } die(); ?> <div id="content"> <div class="content_item"> <h2>contact me!</h2> <p>whether have constructive criticism, advise, questions, or request, place it! </p> <form name="htmlform" method="post" action="http://localhost/html_form_send.php"> <div style="width:170px; float:left;"><p><label for="first_name">first name *</label></p></div> <div style="width:430px; float:right;"><p><input class="contact" type="text" name="first_name" value="" /></p></div> <div style="width:170px; float:left;"><p><label for="last_name">last name </label></p></div> <div style="width:430px; float:right;"><p><input class="contact" type="text" name="last_name" value="" /></p></div> <div style="width:170px; float:left;"><p><label for="email">email address * </label></p></div> <div style="width:430px; float:right;"><p><input class="contact" type="text" name="email" value="" /></p></div> <div style="width:170px; float:left;"><p><label for="telephone">phone number </label></p></div> <div style="width:430px; float:right;"><p><input class="contact" type="text" name="phone" value="" /></p></div> <div style="width:170px; float:left;"><p><label for="comments">message *</label></p></div> <div style="width:430px; float:right;"><p><textarea class="contact textarea" rows="8" cols="50" name="message"></textarea></p></div> <br style="clear:both;" /> <p style="padding: 10px 0 10px 0;">please come in reply simple math question (to prevent spam)</p> <div style="width:170px; float:left;"><p>maths question: 9 + 3 = ?</p></div> <div style="width:430px; float:right;"> <p><input type="text" name="user_answer" class="contact" /><input type="hidden" name="answer" value="4d76fe9775"/></p> </div> <div style="width:430px; float:right;"> <p style="padding-top: 15px"><form action="index.php"><input type="submit" value="submit"></p> </div> </form> </div><!--close content_item-->

any help much appreciated, give thanks much!

change:

<textarea class="contact textarea" rows="8" cols="50" name="message"></textarea>

to:

<textarea class="contact textarea" rows="8" cols="50" name="comments"></textarea>

you have set name of html textarea message testing textarea named comments in php code.

also @fred-ii pointed out, testing telephone in post, value in html phone

and remove - <form action="index.php"> creates sec form!

btw, should take half effort of posting question in so, run quick debug echo/print_r/error_reporting statements , figure out. if planning more programming in future, highly recommend work on debugging skills, way more easier , efficient such little problems. bigger ones, there :-)

not beingness cynical, advice :) best of luck!

php html forms email contact

No comments:

Post a Comment