Ik ben geen goede webmaster maar een beginner.
Ik heb een email template gedownload van een website. Alles werkt behalve wanneer ik het ingevulde formulier wil versturen geeft het een foutmelding namelijk "Could not send mail! Please check your PHP mail configuration."
Kan iemand mij hiermee helpen? Ik heb er al weken aan besteed voor de oplossing maar het lukt niet... :-(
Ik hoop dat jullie me verder kunnen helpen.
HTML CODE:
<!-- 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 -->PHP CODE:
<?php
header('Content-type: application/json');
if($_POST)
{
$to_email = "[email protected]"; //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);
}
}
?>