1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
| <?php
/*
* CONFIGURE EVERYTHING HERE
*/
// an email address that will be in the From field of the email.
//$from = 'devillers@hotmail.fr';
// an email address that will receive the email with the output of the form
$sendTo = 'Formulaire de contact <devillers@developpement-durable.gouv.fr>';
// subject of the email
$subject = 'Nouveau message de Formulaire de contact ';
// form field names and their translations.
// array variable name => Text to appear in the email
$fields = array('name' => 'Nom', 'telephone' => 'Téléphone', 'need' => 'Besoin', 'email' => 'Email', 'message' => 'Message');
// message that will be displayed when everything is OK :)
$okMessage = 'Formulaire de contact bien envoyé. Merci et à bientôt!';
// If something goes wrong, we will display this message.
$errorMessage = 'Problème pour faire parvenir le message ; Rééssayez plus tard.';
/*
* LET'S DO THE SENDING
*/
// if you are not debugging and don't need error reporting, turn this off by error_reporting(0);
error_reporting(E_ALL & ~E_NOTICE);
try
{
if(count($_POST) == 0) throw new \Exception('Form is empty');
$emailText = "Vous avez un nouveau message de votre formulaire de contact\n=============================\n";
foreach ($_POST as $key => $value) {
// If the field exists in the $fields array, include it in the email
if (isset($fields[$key])) {
$emailText .= "$fields[$key]: $value\n";
}
}
// All the neccessary headers for the email.
//$headers = array('Content-Type: text/plain; charset="UTF-8";',
//'From: ' . $from_name,
//'Reply-To: ' . $from,
// 'Return-Path: ' . $from,
//);
// En-têtes additionnels
$headers[] = 'MIME-Version: 1.0';
$headers[] .= 'Content-type: text/html; charset=UTF-8';
$headers[] .= 'Sensitivity: Normal\n';
$headers[] = 'To: JCD <devillers@developpement-durable.fr>'; // boîte thunderbird
$headers[] = 'From: Formulaire de contact <devillers@hotmail.fr>';
// Send email
$status = mail($sendTo, $subject, $emailText, implode("\r\n", $headers));
//$status = mail($sendTo, $subject, $emailText, implode("\n", $headers));
$responseArray = array('type' => 'success', 'message' => $okMessage);
}
catch (\Exception $e)
{
$responseArray = array('type' => 'danger', 'message' => $errorMessage);
}
// if requested by AJAX request return JSON response
if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
$encoded = json_encode($responseArray);
header('Content-Type: application/json');
echo $encoded;
}
// else just display the message
else {
echo $responseArray['message'];
}
$header .= "Content-type: text/plain; charset=utf-8\r\n";
$destinataire=$_POST['email'];
mail($destinataire, 'Accusé de réception', 'Votre mail a bien été envoyé sur le site : site.fr , MERCI', $header); |
Partager