PHP Mail Form doesn't work, Problems with my PHP Mail form |
PHP Mail Form doesn't work, Problems with my PHP Mail form |
Eelco 1985 |
Feb 13 2016, 03:58 PM
Post
#1
|
Group: Members Posts: 1 Joined: 13-February 16 Member No.: 23,996 |
Hi there,
I'm not a good webmaster. I'm a beginner. I downloaded a template email form from a website. Everything is working except the sending of the form. I get an error: "Could not send mail! Please check your PHP mail configuration." Can anybody help me with this. Spend my whole weekend on it. Enoying!! This is my HTML code: QUOTE <!-- Contact section --> <section id="contact" class="contact content-section no-bottom-pad"> <div class="container"> <div class="row text-center"> <div class="col-md-12"> <h2>Contact</h2> <h3 class="caption gray">Neem gerust contact met ons op als je denkt dat wij je ergens mee kunnen helpen.</h3> </div><!-- /.col-md-12 --> </div><!-- /.row --> </div><!-- /.container --> <div class="container"> <div class="row form-container"> <div class="col-md-8 contact-form"> <h3>Laat een bericht achter</h3> <form class="ajax-form" id="contactForm" method="post" action="assets/php/contact.php"> <div class="form-group"> <input type="text" class="form-control" id="name" name="name" placeholder="Jouw naam..." value="" required> </div> <div class="form-group"> <input type="email" class="form-control" id="email" name="email" placeholder="Jouw email..." value="" required> </div> <div class="form-group"> <input type="phone" class="form-control" id="phone" name="phone" placeholder="Jouw telefoonnummer..." value="" required> </div> <div class="form-group"> <textarea class="form-control" rows="4" name="message" placeholder="Jouw bericht..." required></textarea> </div> <div class="form-group"> <button type="submit" name="submit" class="btn btn-default"><i class="fa fa-paper-plane fa-fw"></i>Verzenden</button> </div> </form> </div><!-- /.contact-form --> And this is my PHP code: QUOTE <?php header('Content-type: application/json'); if($_POST) { $to_email = "info@force10.tv"; //Recipient email, Replace with own email here //check if its an ajax request, exit if not if(!isset($_SERVER['HTTP_X_REQUESTED_WITH']) AND strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) != 'xmlhttprequest') { $output = json_encode(array( //create JSON data 'type'=>'error', 'text' => 'Sorry Request must be Ajax POST' )); die($output); //exit script outputting json data } //Sanitize input data using PHP filter_var(). $user_name = filter_var($_POST["name"], FILTER_SANITIZE_STRING); $user_email = filter_var($_POST["email"], FILTER_SANITIZE_EMAIL); $phone_number = filter_var($_POST["phone"], FILTER_SANITIZE_NUMBER_INT); $message = filter_var($_POST["message"], FILTER_SANITIZE_STRING); //additional php validation if(strlen($user_name)<4){ // If length is less than 4 it will output JSON error. $output = json_encode(array('type'=>'error', 'text' => 'Naam is te kort of leeg')); die($output); } if(!filter_var($user_email, FILTER_VALIDATE_EMAIL)){ //email validation $output = json_encode(array('type'=>'error', 'text' => 'Vul alsjeblieft een geldig email in')); die($output); } if(!filter_var($phone_number, FILTER_SANITIZE_NUMBER_FLOAT)){ //check for valid numbers in phone number field $output = json_encode(array('type'=>'error', 'text' => 'Voer alleen cijfers in')); die($output); } if(strlen($message)<3){ //check emtpy message $output = json_encode(array('type'=>'error', 'text' => 'Sorry, een te kort bericht. Vul iets in')); die($output); } //email subject $subject ='Bericht via de website Force 10'; //email body $message_body = $message."\r\n\r\n-".$user_name."\r\n\r\nEmail : ".$user_email."\r\nPhone Number : ". $phone_number ; //proceed with PHP email. $headers = 'From: '.$user_name.'<'.$user_email.'>'."\r\n" . 'Reply-To: '.$user_name.'<'.$user_email.'>' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); $send_mail = mail($to_email, $subject, $message_body, $headers); if(!$send_mail) { //If mail couldn't be sent output error. Check your PHP email configuration (if it ever happens) $output = json_encode(array('type'=>'error', 'text' => 'Could not send mail! Please check your PHP mail configuration.')); die($output); }else{ $output = json_encode(array('type'=>'success', 'text' => 'Hi '.$user_name .', Bedankt voor je bericht. We zullen zsm contact opnemen.')); die($output); } } ?> This is my email form on my website: Many thanks in advance. Best, Eelco |
Lo-Fi Version | Time is now: 26th April 2024 - 11:44 PM |