Merci beaucoup. Par contre je viens de remarquer quelque chose d'assez étrange, quand je mets des espaces dans ma variable subject, qui se réfère au champs objet, le mail ne s'envoie pas et a contrario quand je n'en mets pas, le mail s'envoie, et ça fait ça seulement sur ce champs..
Je reposte mon code pour ceux qui veulent :
<?php
ini_set('display_errors', '1');
error_reporting(E_ALL);
//If the form is submitted
if(isset($_POST['btn-submit-form-contact'])) {
//Check to make sure sure that a valid email address is submitted
if(trim($_POST['email']) == '') {
$hasError = true;
} else if (!filter_var( trim($_POST['email'], FILTER_VALIDATE_EMAIL ))) {
$hasError = true;
} else {
$email = trim($_POST['email']);
}
//Check to make sure that the subject field is not empty
if(trim($_POST['subject']) == '') {
$hasError = true;
} else {
$subject = trim($_POST['subject']);
}
//Check to make sure that the second name field is not empty
if(trim($_POST['contact_second_name']) == '') {
$hasError = true;
} else {
$second_name = trim($_POST['contact_second_name']);
}
//Check to make sure that the first name field is not empty
if(trim($_POST['contact_first_name']) == '') {
$hasError = true;
} else {
$first_name = trim($_POST['contact_first_name']);
}
//Check to make sure comments were entered
if(trim($_POST['message']) == '') {
$hasError = true;
} else {
if(function_exists('stripslashes')) {
$message = htmlentities(trim($_POST['message']));
} else {
$message = trim($_POST['message']);
}
}
//If there is no error, send the email
if(!isset($hasError)){
$mail = '[email protected]'; // Déclaration de l'adresse de destination.
if (!preg_match("#^[a-z0-9._-]+@(hotmail|live|msn).[a-z]{2,4}$#", $mail)) // On filtre les serveurs qui présentent des bogues.
{
$passage_ligne = "\r\n";
}
else
{
$passage_ligne = "\n";
}
//Déclaration des messages au format texte et au format HTML.
$message_html =
"<html>
<head>
</head>
<body><h1><center>Formulaire de contact</center></h1>"
.
"<br /><strong>" . htmlentities($_POST['contact_first_name']) . " " . htmlentities($_POST['contact_second_name']) . "</strong>"
. " " . "vous a contacté, en raison de : " . htmlentities($_POST['subject']) . "<br /> <br />" . htmlentities($_POST['message']) .
"<br /></body>
</html>";
//Création de la boundary
$boundary = "-----=".md5(rand());
//Définition du sujet.
$sujet = htmlentities($_POST['subject']);
//
//Création du header de l'e-mail.
$header = "From: \"".htmlentities($_POST['contact_first_name']) .htmlentities($_POST['contact_second_name'])."\"<".$email.">".$passage_ligne;
$header.= "Reply-to: \"".htmlentities($_POST['contact_first_name']) . htmlentities($_POST['contact_second_name'])."\"<".$email.">".$passage_ligne;
$header.= "MIME-Version: 1.0".$passage_ligne;
$header.= "X-Priority: 3".$passage_ligne;
$header.= "X-Confirm-Reading-To: ".$email.$passage_ligne;
$header.= "Content-Type: text/html; charset=\"utf8\"".$passage_ligne."$boundary".$passage_ligne;
//
//Ajout du message au format HTML
$message= $passage_ligne.$message_html.$passage_ligne;
$message.= $passage_ligne."--".$boundary."--".$passage_ligne;
//
/* Expression régulière permettant de vérifier qu'aucun en-tête n'est inséré dans nos champs */
$regex_head = '/[\n\r]/';
/* On vérifie qu'il n'y a aucun header dans les champs */
if (preg_match($regex_head, $email)
|| preg_match($regex_head, $_POST['contact_first_name'])
|| preg_match($regex_head, $_POST['contact_second_name'])
|| preg_match($regex_head, $_POST['subject'])
|| preg_match($regex_head, $_POST['message']))
{
$alert = setAlert('Entêtes interdites dans les champs du formulaire', 'danger');
}
else
{
//Envoi de l'e-mail.
if (mail($mail,$sujet,$message,$header)){
setAlert('Le mail a bien été envoyé', 'success');
}
else
setAlert('Echec de l\' envoi du mail', 'danger');
}
}
/* On affiche l'erreur s'il y en a une */
if (!empty($alert))
{
echo $alert;
}
}
?>
Merci beaucoup. Par contre je viens de remarquer quelque chose d'assez étrange, quand je mets des espaces dans ma variable subject, qui se réfère au champs objet, le mail ne s'envoie pas et a contrario quand je n'en mets pas, le mail s'envoie, et ça fait ça seulement sur ce champs..
Je reposte mon code pour ceux qui veulent :
[php]
<?php
ini_set('display_errors', '1');
error_reporting(E_ALL);
//If the form is submitted
if(isset($_POST['btn-submit-form-contact'])) {
//Check to make sure sure that a valid email address is submitted
if(trim($_POST['email']) == '') {
$hasError = true;
} else if (!filter_var( trim($_POST['email'], FILTER_VALIDATE_EMAIL ))) {
$hasError = true;
} else {
$email = trim($_POST['email']);
}
//Check to make sure that the subject field is not empty
if(trim($_POST['subject']) == '') {
$hasError = true;
} else {
$subject = trim($_POST['subject']);
}
//Check to make sure that the second name field is not empty
if(trim($_POST['contact_second_name']) == '') {
$hasError = true;
} else {
$second_name = trim($_POST['contact_second_name']);
}
//Check to make sure that the first name field is not empty
if(trim($_POST['contact_first_name']) == '') {
$hasError = true;
} else {
$first_name = trim($_POST['contact_first_name']);
}
//Check to make sure comments were entered
if(trim($_POST['message']) == '') {
$hasError = true;
} else {
if(function_exists('stripslashes')) {
$message = htmlentities(trim($_POST['message']));
} else {
$message = trim($_POST['message']);
}
}
//If there is no error, send the email
if(!isset($hasError)){
$mail = '
[email protected]'; // Déclaration de l'adresse de destination.
if (!preg_match("#^[a-z0-9._-]+@(hotmail|live|msn).[a-z]{2,4}$#", $mail)) // On filtre les serveurs qui présentent des bogues.
{
$passage_ligne = "\r\n";
}
else
{
$passage_ligne = "\n";
}
//Déclaration des messages au format texte et au format HTML.
$message_html =
"<html>
<head>
</head>
<body><h1><center>Formulaire de contact</center></h1>"
.
"<br /><strong>" . htmlentities($_POST['contact_first_name']) . " " . htmlentities($_POST['contact_second_name']) . "</strong>"
. " " . "vous a contacté, en raison de : " . htmlentities($_POST['subject']) . "<br /> <br />" . htmlentities($_POST['message']) .
"<br /></body>
</html>";
//Création de la boundary
$boundary = "-----=".md5(rand());
//Définition du sujet.
$sujet = htmlentities($_POST['subject']);
//
//Création du header de l'e-mail.
$header = "From: \"".htmlentities($_POST['contact_first_name']) .htmlentities($_POST['contact_second_name'])."\"<".$email.">".$passage_ligne;
$header.= "Reply-to: \"".htmlentities($_POST['contact_first_name']) . htmlentities($_POST['contact_second_name'])."\"<".$email.">".$passage_ligne;
$header.= "MIME-Version: 1.0".$passage_ligne;
$header.= "X-Priority: 3".$passage_ligne;
$header.= "X-Confirm-Reading-To: ".$email.$passage_ligne;
$header.= "Content-Type: text/html; charset=\"utf8\"".$passage_ligne."$boundary".$passage_ligne;
//
//Ajout du message au format HTML
$message= $passage_ligne.$message_html.$passage_ligne;
$message.= $passage_ligne."--".$boundary."--".$passage_ligne;
//
/* Expression régulière permettant de vérifier qu'aucun en-tête n'est inséré dans nos champs */
$regex_head = '/[\n\r]/';
/* On vérifie qu'il n'y a aucun header dans les champs */
if (preg_match($regex_head, $email)
|| preg_match($regex_head, $_POST['contact_first_name'])
|| preg_match($regex_head, $_POST['contact_second_name'])
|| preg_match($regex_head, $_POST['subject'])
|| preg_match($regex_head, $_POST['message']))
{
$alert = setAlert('Entêtes interdites dans les champs du formulaire', 'danger');
}
else
{
//Envoi de l'e-mail.
if (mail($mail,$sujet,$message,$header)){
setAlert('Le mail a bien été envoyé', 'success');
}
else
setAlert('Echec de l\' envoi du mail', 'danger');
}
}
/* On affiche l'erreur s'il y en a une */
if (!empty($alert))
{
echo $alert;
}
}
?>
[/php]