Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2018
402
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.01 KB | None | 0 0
  1. <?php
  2.     require_once('./vendor/autoload.php'); //Inclus un autoload qui charge tout les plugins de composer que tu ajoutes
  3.  if(isset($_POST['submit'])) {
  4.    //Ici on vérifie si le form est envoyé, si oui on traite tout
  5.    
  6.         if(isset($_POST['nom'])){
  7.          
  8.             $nom = $_POST['nom'];
  9.            
  10.         }
  11.         if(isset($_POST['sujet'])){
  12.            
  13.             $sujet = $_POST['sujet'];
  14.            
  15.         }
  16.         if(isset($_POST['message'])){
  17.            
  18.             $message = $_POST['message'];
  19.         }
  20.         if(isset($_POST['email'])){
  21.  
  22.             $email = $_POST['email'];
  23.         }
  24.  
  25.  
  26.    
  27.  
  28.        //-----------------------------------------------
  29.        //DECLARE LES VARIABLES ICI
  30.        //-----------------------------------------------
  31.         //Ici on appelle le plugin php mailer
  32.  
  33.   $phpmailer = new \PHPMailer\PHPMailer\PHPMailer();
  34.        
  35.           // Set Psmtp ou mail basique
  36.       $phpmailer-> IsSMTP(); //Quand ton site sera héberger sur un serveur en ligne ça marchera, en attendant faut que tu test avec mailtrap.io par exemple qui te propose un serveur smtp de test gratuitement poue t'es tst à la place de isSendMail tu met
  37.       //Enable SMTP debugging
  38.       // 0 = off (for production use)
  39.       // 1 = client messages
  40.       // 2 = client and server messages
  41.       $phpmailer->SMTPDebug = 2;
  42.       //Set the hostname of the mail server
  43.       $phpmailer->Host = 'smtp.mailtrap.io';
  44.       // use
  45.       // $mail->Host = gethostbyname('smtp.gmail.com');
  46.       // if your network does not support SMTP over IPv6
  47.       //Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
  48.       $phpmailer->Port =  2525;
  49.       //Set the encryption system to use - ssl (deprecated) or tls
  50.       $phpmailer->SMTPSecure = 'Optional';
  51.       //Whether to use SMTP authentication
  52.       $phpmailer->SMTPAuth = true;
  53.       //Username to use for SMTP authentication - use full email address for gmail
  54.       $phpmailer->Username = "c66742f0221526"; //ton mail
  55.       //Password to use for SMTP authentication
  56.       $phpmailer->Password = "f774e5e1c5d75d"; //ton pass (tkt je regarde pas ^)
  57.       //Mail de qui ?
  58.       $phpmailer->setFrom('from@example.com', 'First Last');
  59.       // réponse a qui
  60.       $phpmailer->addReplyTo('replyto@example.com', 'First Last');
  61.       //envoyer a qui ?
  62.       $phpmailer->addAddress('nadiatech01@gmail.com', 'John Doe');
  63.       //Sujet
  64.       $phpmailer->Subject = 'PHPMailer sendmail test';
  65.       //Message en html
  66.       $phpmailer->msgHTML("<h1>Contact</h1>");
  67.       //Message en texte si le html ne s'affiche pas chez les gens
  68.        $message =  "\r\n Nom: " . $_POST['nom'] . "\r\n Sujet: " . $_POST['sujet'] . "\r\n Email: " . $_POST['email'] . "\r\n Message: " . $_POST['message'];
  69.        $phpmailer->AltBody = $message;
  70.    
  71.     //on envoie ou on affiche une erreur
  72.     if (!$phpmailer->send()) {
  73.          header('Location: demande.html');
  74.        
  75.     } else {
  76.         header('Location: demande.html');
  77.     }
  78.   }
  79.     ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement