Erreur lors de la soumission du formulaire de contact.Erreur lors de la soumission du formulaire de contact
Undefined index: HTTP_X_REQUESTED_WITH dans C: \ xampp \ htdocs \ dishadwellings \ dishaparkwest \ contact.php sur la ligne 7 { "type": "erreur", "texte": "Désolé demande doit être Ajax POST" }
Voici le code HTML FORM:
<form action="contact.php" method="POST">
<input type="text" name="do-input-name" id="do-input-name" placeholder="Name">
<input type="email" name="do-input-email" id="do-input-email" placeholder="Email">
<input type="text" name="do-input-web" id="do-input-web" placeholder="Web">
<textarea name="do-input-message" id="do-input-message" cols="30" rows="10" class="do-input-message" placeholder="Comment"></textarea>
<button type="submit" id="do-submit-btn" class="do-btn-round-solid">SEND</button>
</form>
Voici le code pour le formulaire de contact: Je ne pouvais pas corriger l'erreur. Veuillez faire la faveur de résoudre ce problème
<?php
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().
$name = filter_var($_POST["name"], FILTER_SANITIZE_STRING);
$email = filter_var($_POST["email"], FILTER_SANITIZE_EMAIL);
$message = filter_var($_POST["message"], FILTER_SANITIZE_STRING);
//additional php validation
if(strlen($name)<4){ // If length is less than 4 it will output JSON error.
$output = json_encode(array('type'=>'error', 'text' => 'Name is too short or empty!'));
die($output);
}
if(!filter_var($email, FILTER_VALIDATE_EMAIL)){ //email validation
$output = json_encode(array('type'=>'error', 'text' => 'Please enter a valid email!'));
die($output);
}
if(strlen($message)<3){ //check emtpy message
$output = json_encode(array('type'=>'error', 'text' => 'Too short message! Please enter something.'));
die($output);
}
//email body
$message_body = $message."\r\n\r\n-".$name."\r\nEmail : ".$email;
//proceed with PHP email.
$headers = 'From: '.$name.'' . "\r\n" .
'Reply-To: '.$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'=>'message', 'text' => 'Hi '.$user_name .' Thank you for your email'));
die($output);
}
}
?>
publiez aussi votre code .. –
Donnez ici le code ajax qui fait cela soumettre – Rupal
Je poste le code. – Saranya