goltoof Posted February 10, 2015 Share Posted February 10, 2015 Trying to get a contact form which came with a TF template (the author is not responding). Sort of need it fixed asap.The documentation simply states change the email to the send email but the page throws and error and no message is sent. Is there any obvious reason why this form wouldn't work out of the box? I tried a couple other contact forms and they work just fine on the server.code for displaying the form <form id="contactForm" action="contact.php" method="post"> <div class="inner"> <i class="icon-useralt"></i> <input name="senderName" id="senderName" required="required" type="text" placeholder="Name" /> </div> <div class="inner"> <i class="icon-envelope"></i> <input type="email" name="senderEmail" id="senderEmail" placeholder="Email address" required="required" /> </div> <div class="inner"> <i class="icon-pencil"></i> <textarea name="message" id="message" placeholder="Message" rows="5"></textarea> </div> <input type="submit" id="sendMessage" name="sendMessage" value="Submit message" /> </form> contact.php <?php if(!$_POST) exit; $email = $_POST['email']; //$error[] = preg_match('/\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i', $_POST['email']) ? '' : 'INVALID EMAIL ADDRESS'; if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$email )){ $error.="Invalid email address entered"; $errors=1; } if($errors==1) echo $error; else{ $values = array ('name','email','message'); $required = array('name','email','message'); $your_email = "mail@example.com"; $email_subject = $_POST['subject']."\n";; $email_content = "new message:\n"; foreach($values as $key => $value){ if(in_array($value,$required)){ if ($key != 'subject') { if( empty($_POST[$value]) ) { echo 'PLEASE FILL IN REQUIRED FIELDS'; exit; } } $email_content .= $value.': '.$_POST[$value]."\n"; } } if(@mail($your_email,$email_subject,$email_content)) { echo 'Message sent!'; } else { echo 'ERROR!'; Quote Link to comment https://forums.phpfreaks.com/topic/294510-need-help-with-a-contact-form/ Share on other sites More sharing options...
cyberRobot Posted February 10, 2015 Share Posted February 10, 2015 It looks like the form field names don't match the names used in the email script. Your email field, for example, is named "senderEmail". <input type="email" name="senderEmail" ... And the email script uses "email". $email = $_POST['email']; In case you're not aware, you can tell PHP to show all errors and warnings by adding the following to the top of your email script: <?php error_reporting(E_ALL); ini_set('display_errors', 1); ?> Of course you'll want to remove the error-reporting code once you're done debugging. Quote Link to comment https://forums.phpfreaks.com/topic/294510-need-help-with-a-contact-form/#findComment-1505359 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.