Viewing file: submitemail.php (2.38 KB) -rw----r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php
$nom = ''; $tel = ''; $email = ''; $message = ''; $ville = '';
function getIp() { if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { $ip_address = $_SERVER['HTTP_X_FORWARDED_FOR']; }
if (!isset($ip_address)) { if (isset($_SERVER['REMOTE_ADDR'])) $ip_address = $_SERVER['REMOTE_ADDR']; } return $ip_address; }
//taking the data from form
$nom = addslashes(trim($_POST['nom'])); $tel = addslashes(trim($_POST['tel'])); $email = addslashes(trim($_POST['email'])); $ville = addslashes(trim($_POST['ville'])); $message = addslashes(trim($_POST['message']));
//form validation $errors = array(); $fields = array(); if (!$nom) { $errors[] = "Please enter your name."; $fields[] = "nom"; }
if (!$tel) { $errors[] = "Please choose the subject of your message."; $fields[] = "tel"; } if (!$message) { $errors[] = "Please enter your message."; $fields[] = "message"; }
//preparing mail if (!$errors) { //taking info about date, IP and user agent $timestamp = date("Y-m-d H:i:s"); $ip = getIp(); $host = gethostbyaddr($ip); $user_agent = $_SERVER["HTTP_USER_AGENT"];
$headers = "MIME-Version: 1.0\n"; $headers .= "Content-type: text/html; charset=utf-8\n"; $headers .= "Content-Transfer-Encoding: quoted-printable\n"; //$headers .= "From: $email\n";
$content = 'Sujet: Demande de contact<br>' . 'Nom: ' . $nom . '<br>' . 'Tél: ' . $tel . '<br>' . 'Ville: ' . $ville . '<br>' . 'Email: ' . $email . '<br>' . 'Message: ' . nl2br($message) . '<br>' . 'à : ' . $timestamp . '<br>' . 'IP: ' . $host . '<br>'; //'User agent: '.$user_agent; //sending mail ebenisteriedandres@gmail.com $ok = mail("ebenisteriedandres@gmail.com", "Demande de contact", $content, $headers); if ($ok) { $response['msgStatus'] = "ok"; $response['message'] = "Merci de nous contacter. Nous répondrons à votre demande dès que possible."; } else { $response['msgStatus'] = "error"; $response['message'] = "Une erreur s'est produite lors de l'envoi de votre message. S'il vous plaît réessayer plus tard."; } } else { $response['msgStatus'] = "error"; $response['errors'] = $errors; $response['errorFields'] = $fields; }
header('Content-type: application/json'); echo json_encode($response); ?>
|