KfirLankry Posted January 10, 2015 Share Posted January 10, 2015 (edited) hey, ive edit a contact form i found on net, changed everything i needed, when i click the "submit" button it shows that the form was send succsesfuly but nothing comes up in the email.. what is wrong ? form code html: <form method="post" action="../booking/booking.php" id="contactform"> <div class="form"> <div class="six columns noleftmargin"> <label>* Company name:</label> <input type="text" name="companyname" class="smoothborder" placeholder="* Company name"/> </div> <div class="six columns noleftmargin"> <label>* Contact name:</label> <input type="text" name="contactname" class="smoothborder" placeholder="* Contact name"/> </div> <p> <div class="six columns noleftmargin"> <label>* Event country:</label> <input type="text" name="country" class="smoothborder" placeholder="* Event country"/> </div> <div class="six columns noleftmargin"> <label>* Event city:</label> <input type="text" name="city" class="smoothborder" placeholder="* Event city"/> </div> <p> <div class="six columns noleftmargin"> <label>* Phone number:</label> <input type="text" name="phone" class="smoothborder" placeholder="* Phone number"/> </div> <div class="six columns noleftmargin"> <label>* Email adress:</label> <input type="text" name="email" class="smoothborder" placeholder="* Email adress"/> <label for="select"></label> </div> <div class="six columns noleftmargin"> <label>* Skype:</label> <input type="text" name="skype" class="smoothborder" placeholder="* Skype"/> <label for="select"></label> </div> <div class="six columns noleftmargin"> <label>* Aritst:</label> <input type="text" name="artist" class="smoothborder" placeholder="* Artist"/> <br> <label for="select"></label> </div> <p> <input type="submit" id="submit" class="readmore" value="Submit"> </p> PHP code: <?php if(isset($_POST['email'])) { // EDIT THE 2 LINES BELOW AS REQUIRED $email_to = "info@bouncerecordings.com"; $email_subject = "Booking Request"; 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['companyname']) || !isset($_POST['contactname']) || !isset($_POST['country']) || !isset($_POST['city']) || !isset($_POST['phone']) || !isset($_POST['email']) || !isset($_POST['skype']) || !isset($_POST['artist'])) { died('We are sorry, but there appears to be a problem with the form you submitted.'); } $companyname = $_POST['companyname']; // required $contactname = $_POST['contactname']; // required $country = $_POST['country']; // required $city = $_POST['city']; // required $phone = $_POST['phone']; // required $email = $_POST['email']; // required $skype = $_POST['skype']; // not required $artist = $_POST['artist']; // required $error_message = ""; $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/'; if(!preg_match($email_exp,$email)) { $error_message .= 'The Email Address you entered does not appear to be valid.<br />'; } $string_exp = "/^[A-Za-z .'-]+$/"; if(!preg_match($string_exp,$companyname)) { $error_message .= 'The First Name you entered does not appear to be valid.<br />'; } if(!preg_match($string_exp,$contactname)) { $error_message .= 'The Last Name you entered does not appear to be valid.<br />'; } if(!preg_match($string_exp,$country)) { $error_message .= 'The Last Name you entered does not appear to be valid.<br />'; } if(!preg_match($string_exp,$city)) { $error_message .= 'The Last Name you entered does not appear to be valid.<br />'; } if(!preg_match($string_exp,$phone)) { $error_message .= 'The Last Name you entered does not appear to be valid.<br />'; } if(!preg_match($string_exp,$skype)) { $error_message .= 'The Last Name you entered does not appear to be valid.<br />'; } if(!preg_match($string_exp,$artist)) { $error_message .= 'The Last Name you entered does 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 .= "Company Name: ".clean_string($companyname)."\n"; $email_message .= "Contact Name: ".clean_string($contactname)."\n"; $email_message .= "Country: ".clean_string($country)."\n"; $email_message .= "City: ".clean_string($city)."\n"; $email_message .= "Phone Number: ".clean_string($phone)."\n"; $email_message .= "Email: ".clean_string($email)."\n"; $email_message .= "Skype: ".clean_string($skype)."\n"; $email_message .= "Artist: ".clean_string($artist)."\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 --> Thank you for contacting us. We will be in touch with you very soon. <?php } ?> Edited January 10, 2015 by KfirLankry Quote Link to comment https://forums.phpfreaks.com/topic/293805-contact-form-problem/ Share on other sites More sharing options...
Frank_b Posted January 10, 2015 Share Posted January 10, 2015 first of all: place a echo 'test'; just above the mail() function so that you are sure that your code reaches this part of code. second: remove that @ before the mail function. Don't you want to be informed if an error occurs?? third: give an error if the mail function returns a FALSE. if(mail(...) === FALSE) echo 'Sorry your email could not be sent.'; Quote Link to comment https://forums.phpfreaks.com/topic/293805-contact-form-problem/#findComment-1502396 Share on other sites More sharing options...
Frank_b Posted January 10, 2015 Share Posted January 10, 2015 fourth: if u still dont get your email (check your spam also) then you might try to send a very simple email like this: mail('myself@myhost.com','Test mail', 'Just a test...'); If then there is still no email then you have to contact your provider. Maybe they blocked the email() function of maybe you have to send your email through a SMTP server. In that case you could use a library like PHPMailer or Swiftmailer. Quote Link to comment https://forums.phpfreaks.com/topic/293805-contact-form-problem/#findComment-1502397 Share on other sites More sharing options...
Barand Posted January 10, 2015 Share Posted January 10, 2015 Have you configured your php.ini file for mail http://www.quackit.com/php/tutorial/php_mail_configuration.cfm Quote Link to comment https://forums.phpfreaks.com/topic/293805-contact-form-problem/#findComment-1502398 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.