Bonjour,
J'ai un projet de site avec formulaire . pour etre plus precis j'ai 3 formulaires . J'ai reussi faire la recupération des fichier avec php j'utilise mailtrap et laragon . le probkème c'est que je recois un long message d'erreur sur mes pages de formulaire . J'ai essayer de l'arranger mais ca n'a marcher que pour une seule page , bien que lorsque j'ouvre mes pae il n'ya plus de message d'erreur, lorsque je clique sur envoyer ca envois les données mais ca me redirige vers la meme page avec le meme long messae d'erreur que j'ai enlever .
Voici le code qui marche :

<?php
    require_once('./vendor/autoload.php'); //Inclus un autoload qui charge tout les plugins de composer que tu ajoutes
 if(isset($_POST['submit'])) {

        if(isset($_POST['nom'])){

            $nom = $_POST['nom'];

        }
        if(isset($_POST['sujet'])){

            $sujet = $_POST['sujet'];

        }
        if(isset($_POST['message'])){

            $message = $_POST['message'];
        }
        if(isset($_POST['email'])){

            $email = $_POST['email'];
        }

   htmlspecialchars(strip_tags(trim($_POST['nom'])));

  $phpmailer = new \PHPMailer\PHPMailer\PHPMailer();

          // Set Psmtp ou mail basique
      $phpmailer-> IsSMTP(); 
      //Enable SMTP debugging
      // 0 = off (for production use)
      // 1 = client messages
      // 2 = client and server messages
      $phpmailer->SMTPDebug = 2;
      //Set the hostname of the mail server
      $phpmailer->Host = 'smtp.mailtrap.io';
      // use
      // $mail->Host = gethostbyname('smtp.gmail.com');
      // if your network does not support SMTP over IPv6
      //Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
      $phpmailer->Port =  2525;
      //Set the encryption system to use - ssl (deprecated) or tls
      $phpmailer->SMTPSecure = 'Optional';
      //Whether to use SMTP authentication
      $phpmailer->SMTPAuth = true;
      //Username to use for SMTP authentication - use full email address for gmail
      $phpmailer->Username = "c66742f0221526"; //ton mail
      //Password to use for SMTP authentication
      $phpmailer->Password = "f774e5e1c5d75d"; //ton pass (tkt je regarde pas ^)
      //Mail de qui ?
      $phpmailer->setFrom('from@example.com', 'First Last');
      // réponse a qui
      $phpmailer->addReplyTo('replyto@example.com', 'First Last');
      //envoyer a qui ?
      $phpmailer->addAddress('test@gmail.com', 'John Doe');
      //Sujet
      $phpmailer->Subject = 'PHPMailer sendmail test';
      //Message en html
      $phpmailer->msgHTML("<h1>Contact</h1>");

       $message =  "\r\n Nom: " . $_POST['nom'] . "\r\n Sujet: " . $_POST['sujet'] . "\r\n Email: " . $_POST['email'] . "\r\n Message: " . $_POST['message'];
       $phpmailer->AltBody = $message;

    if (!$phpmailer->send()) {
         header('Location: demande.html');

    } else {
        header('Location: demande.html');
    }
  }
    ?>

Voici un de ceux qui ne marche pas :

<?php
require_once('./vendor/autoload.php'); //Inclus un autoload qui charge tout les plugins de composer que tu ajoutes
 if(isset($_POST['submit'])) {

if(isset($_POST['nom'])){

    $nom = $_POST['nom'];

}
if(isset($_POST['pays'])){

    $pays = $_POST['pays'];

}
if(isset($_POST['societe'])){

    $societe = $_POST['societe'];

}
if(isset($_POST['tel'])){

    $tel = $_POST['tel'];
}
if(isset($_POST['pays'])){

    $pays = $_POST['pays'];
}

$phpmailer = new \PHPMailer\PHPMailer\PHPMailer();
      $filename = $_FILES["file"]["tmp_name"];
        // Set Psmtp ou mail basique
    $phpmailer-> IsSMTP(); //
    //Enable SMTP debugging
    // 0 = off (for production use)
    // 1 = client messages
    // 2 = client and server messages
    $phpmailer->SMTPDebug = 2;
    //Set the hostname of the mail server
    $phpmailer->Host = 'smtp.mailtrap.io';
    // use
    // $mail->Host = gethostbyname('smtp.gmail.com');
    // if your network does not support SMTP over IPv6
    //Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
    $phpmailer->Port =  2525;
    //Set the encryption system to use - ssl (deprecated) or tls
    $phpmailer->SMTPSecure = 'Optional';
    //Whether to use SMTP authentication
    $phpmailer->SMTPAuth = true;
    //Username to use for SMTP authentication - use full email address for gmail
    $phpmailer->Username = "c66742f0221526"; //ton mail
    //Password to use for SMTP authentication
    $phpmailer->Password = "f774e5e1c5d75d"; //ton pass (tkt je regarde pas ^)
    //Mail de qui ?
    $phpmailer->setFrom('from@example.com', 'First Last');
    // réponse a qui
    $phpmailer->addReplyTo('replyto@example.com', 'First Last');
    //envoyer a qui ?
    $phpmailer->addAddress('test@gmail.com', 'John Doe');
    //Sujet
    $phpmailer->Subject = 'PHPMailer sendmail test';
    //Message en html
    $phpmailer->msgHTML("<h1>Client</h1>");
    //Message en texte si le html ne s'affiche pas chez les gens
     $message =  " Nom: " . $_POST['nom'] . "\r\n Pays: " . $_POST['pays'] . "\r\n tel: " . $_POST['tel'] . "\r\n Societe: " . $_POST['societe']. "\r\n Message: " . $_POST['message']; 
     $phpmailer->AltBody = $message;
    $phpmailer->addAttachment($_FILES['file']['tmp_name'],
                         $_FILES['file']['name']);
    //on envoie ou on affiche une erreur
    if (!$phpmailer->send()) {
         header('Location: demande.html');

    } else {
        header('Location: demande.html');
    }

}

?>

Vici le message d'erreur ( une partie parce qu'il est vraiment long ):

2018-02-26 13:15:55 CLIENT -> SERVER: LnJlbHNQSwECLQAUAAYACAAAACEAlLfbv0QFAADvEAAAEQAAAAAAAAAAAAAAAAD/CAAAd29yZC9k
2018-02-26 13:15:55 CLIENT -> SERVER: b2N1bWVudC54bWxQSwECLQAUAAYACAAAACEArm+SApsGAABRGwAAFQAAAAAAAAAAAAAAAAByDgAA
2018-02-26 13:15:55 CLIENT -> SERVER: d29yZC90aGVtZS90aGVtZTEueG1sUEsBAi0AFAAGAAgAAAAhAFUIlurXAgAAWAYAABEAAAAAAAAA
2018-02-26 13:15:55 CLIENT -> SERVER: AAAAAAAAQBUAAHdvcmQvc2V0dGluZ3MueG1sUEsBAi0AFAAGAAgAAAAhAPWBPX+HAQAABwQAABIA
2018-02-26 13:15:55 CLIENT -> SERVER: AAAAAAAAAAAAAAAARhgAAHdvcmQvZm9udFRhYmxlLnhtbFBLAQItABQABgAIAAAAIQBK2IqSuwAA
2018-02-26 13:15:55 CLIENT -> SERVER: AAQBAAAUAAAAAAAAAAAAAAAAAP0ZAAB3b3JkL3dlYlNldHRpbmdzLnhtbFBLAQItABQABgAIAAAA
2018-02-26 13:15:55 CLIENT -> SERVER: IQCvvVzM3gEAANkDAAAQAAAAAAAAAAAAAAAAAOoaAABkb2NQcm9wcy9hcHAueG1sUEsBAi0AFAAG
2018-02-26 13:15:55 CLIENT -> SERVER: AAgAAAAhAEys9lJLAQAAdQIAABEAAAAAAAAAAAAAAAAA/h0AAGRvY1Byb3BzL2NvcmUueG1sUEsB
2018-02-26 13:15:55 CLIENT -> SERVER: Ai0AFAAGAAgAAAAhANDxl3caBwAA+TkAAA8AAAAAAAAAAAAAAAAAgCAAAHdvcmQvc3R5bGVzLnht
2018-02-26 13:15:55 CLIENT -> SERVER: bFBLBQYAAAAACwALAMECAADHJwAAAAA=
2018-02-26 13:15:55 CLIENT -> SERVER:
2018-02-26 13:15:55 CLIENT -> SERVER: --b1_PiwCBDH0Zm5ZJehiobetGP15FnNNKf9sHtrvODY73U--
2018-02-26 13:15:55 CLIENT -> SERVER:
2018-02-26 13:15:55 CLIENT -> SERVER: .
2018-02-26 13:15:55 SERVER -> CLIENT: 250 2.0.0 Ok: queued
2018-02-26 13:15:55 CLIENT -> SERVER: QUIT
2018-02-26 13:15:55 SERVER -> CLIENT: 221 2.0.0 Bye

Warning: Cannot modify header information - headers already sent by (output started at C:\laragon\www\proplus\vendor\phpmailer\phpmailer\src\SMTP.php:256) in C:\laragon\www\proplus\Formulaire.php on line 82

2 réponses


Salut,

C'est pas un message d'erreur. C'est des messages de debug.
Quand on lit une doc, il faut pas simplement copier / coller, mais il faut comprendre.

C'est cette ligne là qui affiche ce message là, tu la retires, et les messages ne seront plus là.

$phpmailer->SMTPDebug = 2;
ariane O
Auteur

merci pour ton aide ca a marcher