Advertisement
Guest User

Untitled

a guest
May 27th, 2017
558
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.35 KB | None | 0 0
  1. <?php
  2. error_reporting(E_ALL); // Active toute les erreurs ( a ne pas foutre en prod )
  3.  
  4.  
  5. $list_email = array(
  6.       1 =>  "commercial@#.com",
  7.  
  8.       2 => "rh@#.com",
  9.  
  10.       3 => "helpdesk@#.com",
  11.  
  12.       4 => "webagency@#.com",
  13.  
  14.       5 => "sse@#.com",
  15.  
  16.       6 => "sruse@#.com",
  17.  
  18.       7 => "alassane@#.com"
  19. );
  20.  
  21.  
  22. $your_email = intval($_POST['emailaddress']);  // Email qui recevront les messages
  23.  
  24. if(!empty($your_email) && intval($your_email)){
  25.  
  26.   if(!isset($list_email[$your_email]){
  27.      exit("Vous n'avez pas choisi de destinataire");
  28.   }
  29.  
  30.      
  31.  
  32. }
  33.  
  34.  
  35.  
  36. if ($_SERVER['REQUEST_METHOD'] != 'POST') exit; // Quit if it is not a form post
  37.  
  38.  
  39.  
  40. // quick way clean up incoming fields
  41.  
  42. foreach($_POST as $key => $value) $_POST[$key] = urldecode(trim($value));
  43.  
  44.  
  45.  
  46. // get form data into shorter variables
  47.  
  48. // each $_POST variable is named based on the form field's id value
  49.  
  50. $destinataire    = intval($_POST['emailaddress']);
  51.  
  52. $name    = $_POST['sender_name'];
  53.  
  54. $email   = $_POST['sender_email'];
  55.  
  56. $message = $_POST['message'];
  57.  
  58. $code    = $_POST['code'];
  59.  
  60.  
  61.  
  62. $errors  = array(); // array of errors
  63.  
  64.  
  65.  
  66. // basic validation
  67.  
  68. if ($destinataire == 0) {
  69.  
  70.   $errors[] = "- Le champ \"Destinataire\" n'est pas renseigné, merci de rectifier.";
  71.  
  72. }
  73.  
  74.  
  75.  
  76. if ($name == '') {
  77.  
  78.   $errors[] = "- Le champ \"Nom/Prénom\"  n'est pas renseigné, celui-ci doit avoir un minimum de 3 caractères alphabétique a-zA-Z";
  79.  
  80. }elseif(is_int($name)){
  81.  
  82.   $errors[] = "- Le champ \"Nom/Prenom\" ne doit comporter que des caractères alphabétique a-zA-Z";
  83.  
  84. }
  85.  
  86.  
  87.  
  88. /**
  89.  
  90.  * REGEX POUR LA VALIDATION DE L'EMAIL CLIENT
  91.  
  92.  * ([^\D]{0,})(\w+[_\-\.]+\w+)@([a-z0-9]+)\.(\b[a-zA-Z]{2,6}\b)
  93.  
  94.  * babacar.tall@gmail.comhlk
  95.  
  96.   * babacar.tallgmail.com
  97.  
  98.   * babacar.tall_2@gmail.info
  99.  
  100.   * babacar.tall_2@gmail.fr
  101.  
  102.     babacar_tall-34@gm9-ail.com
  103.  
  104.     babacar.tall-@gmail.com
  105.  
  106.     babacar.tall@-gmail.com
  107.  
  108.     babacar.tall@gmail-.com
  109.  
  110.     -babacar.tall-@gmail.com
  111.  
  112.     babacar.tall@gmail.-com
  113.  
  114.     2babacar.tall@gmail.com
  115.  
  116.     2435babacar.tall@gmail.com
  117.  
  118. */
  119.  
  120.  
  121.  
  122. if (empty($email)) {
  123.  
  124.   $errors[] = "- Merci de renseigner le champ \"Email\" avec une adresse correctement remplis et valide";
  125.  
  126. }
  127.  
  128.  
  129.  
  130. if ($message == '' or strlen($message) < 10) {
  131.  
  132.   $errors[] = "- Le champ \"Message\" n'est pas renseigné, celui-ci doit avoir un minimum de 10 caractères";
  133.  
  134. }
  135.  
  136.  
  137.  
  138.  
  139.  
  140. if (sizeof($errors) == 0) {
  141.  
  142.   // only check the code if there are no other errors
  143.  
  144.   require_once '../securimage/securimage.php';
  145.  
  146.   $img = new Securimage;
  147.  
  148.   if ($img->check($code) == false) {
  149.  
  150.     $errors[] = "Merci de renseigner le champ Captcha \"Anti-spam correctement\"";
  151.  
  152.   } // if the code checked is correct, it is destroyed to prevent re-use
  153.  
  154. }
  155.  
  156.  
  157.  
  158. if (sizeof($errors) > 0) {
  159.  
  160.   // if errors, send the error message
  161.  
  162.   $str = implode("\n", $errors);
  163.  
  164.   exit("Il y a une erreur avec votre soumission!\n Assurez-vous d'avoir renseigné tous les champs, et réessayer.\n\n" . $str);
  165.  
  166. }
  167.  
  168.  
  169.  
  170. $time = date('r');
  171.  
  172. $body = <<<EOD
  173.  
  174. Bonjour!
  175.  
  176.  
  177.  
  178. Un message vous a été envoyé à partir de $name à $time.
  179.  
  180.  
  181.  
  182. Voici le message:<br /><br />
  183.  
  184.  
  185.  
  186. $message
  187.  
  188. EOD;
  189.  
  190.  
  191.  
  192. // send email
  193.  
  194. mail($your_email, "Contact Form Sent", $body, "From: $your_email\r\nReply-To: $email\r\nContent-Type: text/plain; charset=ISO-8859-1\r\nMIME-Version: 1.0");
  195.  
  196.  
  197.  
  198. exit('OK'); // send success indicator
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement