<?php
session_start();
$_SESSION['form_element0'] = $_POST['form_element0'];
$_SESSION['form_element1'] = $_POST['form_element1'];
$_SESSION['form_element2'] = $_POST['form_element2'];
$_SESSION['form_element3'] = $_POST['form_element3'];
$_SESSION['form_element4'] = $_POST['form_element4'];
$_SESSION['form_element5'] = $_POST['form_element5'];
$_SESSION['form_element6'] = $_POST['form_element6'];
$form_element0 = $_SESSION['form_element0'];
$form_element1 = preg_replace("/\r/", "", $_SESSION['form_element1']);
$form_element1 = preg_replace("/\n/", "", $form_element1);
$form_element2 = $_SESSION['form_element2'];
$form_element3 = $_SESSION['form_element3'];
$form_element4 = $_SESSION['form_element4'];
$form_element5 = preg_replace("/\r/", "", $_SESSION['form_element5']);
$form_element5 = preg_replace("/\n/", "", $form_element5);
$form_element6 = $_SESSION['form_element6'];
if(!$_SESSION['form_element0'] || !$_SESSION['form_element1'] || !$_SESSION['form_element3'] || !$_SESSION['form_element5'] || !$_SESSION['form_element6']) {
$_SESSION['formMessage'] = "Les champs marqués d’une * sont requis.\n";
Header("Location:../index.php");
exit(); }
elseif (!preg_match('!^[a-zA-Z0-9\.\+_-]+@[a-zA-Z0-9\._-]+\.[a-zA-Z]{2,4}$!U', $_SESSION['form_element4'])) {
$_SESSION['formMessage'] = 'Votre adresse e-mail n\'est pas valide'; Header("Location:../index.php"); exit(); }
else {
$email="[email protected]";
$from = stripslashes($form_element1)."<".stripslashes($form_element1).">";$subject= $form_element5;$message = "\ncivilit?© $form_element0\n\nnom $form_element1\n\npr?©nom $form_element2\n\nt?©l?©phone $form_element3\n\ne-mail $form_element4\n\nobjet $form_element5\n\nmessage $form_element6\n";
$headers="From: $from\n";if (file_exists($tmp_name)){
if(is_uploaded_file($tmp_name)){
$file = fopen($tmp_name,'rb');
$data = fread($file,filesize($tmp_name));
fclose($file);
$data = chunk_split(base64_encode($data));
}
$headers .= "MIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n";
$headers .= " boundary=\"{$mime_boundary}\"";
$message = "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$message . "\n\n";
$message .= "--{$mime_boundary}\n" .
"Content-Type: {$type};\n" .
" name=\"{$name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}--\n";
}
SESSION_UNREGISTER('form_element0');
SESSION_UNREGISTER('form_element1');
SESSION_UNREGISTER('form_element2');
SESSION_UNREGISTER('form_element3');
SESSION_UNREGISTER('form_element4');
SESSION_UNREGISTER('form_element5');
SESSION_UNREGISTER('form_element6');
if (@mail($email, $subject, $message, $headers)) {$_SESSION["formMessage"] = "Merci, votre e-mail a bien été envoyé.";
header("Location: ../index.php");
} else {
$_SESSION["formMessage"] = "Une erreur est survenue. Votre message n'a pas été envoyÈé.";
header("Location: ../index.php");
}
}
?>