Bonjour,

Voila je rencontre un petit problème avec mon code.

Je souhaite créer un formulaire de contact pour un site web.

J'utilise la librairie PHPMailer.

Voici le code mon formulaire :

<!DOCTYPE html>
<html>
<head>
    <title> contact form-php </title>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
</head>
<body>
<div class="container">
    <h2>contact form-php | send email </h2>
        <form method="post" action="email.php">
  <div class="form-group">
    <label for="name">Nom</label>
    <input type="text" name="name" class="form-control" id="name" placeholder="Entrez votre nom">
    <small id="emailHelp" class="form-text text-muted">We'll never share your email with anyone else.</small>
  </div>
  <div class="form-group">
    <label for="email">Entrez votre mail</label>
    <input type="email" name="email" class="form-control" id="email" placeholder="Email">
  </div>
    <div class="form-group">
    <label for="message">Ecrire quelquechose</label>
    <textarea id="message" name="message" class="form-control"></textarea>
  </div>
  <button type="submit" name="submit" class="btn btn-primary">Envoi du mail</button>
        </form>
</body>
</html>

Et voici le code de mon "envoi.php"

<?php

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

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

require 'PHPMailer/src/Exception.php';
require 'PHPMailer/src/PHPMailer.php';
require 'PHPMailer/src/SMTP.php';

$mail = new PHPMailer(true);                              // Passing `true` enables exceptions
try {
    //Server settings
    $mail->SMTPDebug = 0;                                 // Enable verbose debug output
    $mail->isSMTP();                                      // Set mailer to use SMTP
    $mail->Host = 'smtp-mail.outlook.com';  // Specify main and backup SMTP servers
    $mail->SMTPAuth = true;                               // Enable SMTP authentication
    $mail->Username = '*****@hotmail.fr';                 // SMTP username
    $mail->Password = '********';                           // SMTP password
    $mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
    $mail->Port = 587;                                    // TCP port to connect to
    $mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
    //Recipients
    $mail->setFrom('*******@hotmail.fr');
    //$mail->addAddress('joe@example.net', 'Joe User');     // Add a recipient
    //$mail->addAddress('ellen@example.com');               // Name is optional
    $mail->addReplyTo('info@******.com', 'Information');
    $mail->addCC('info@*******.com');
    $mail->addBCC('info@********.com');

    //Attachments
    //$mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
    //$mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name

    //Content
    $mail->isHTML(true);                                  // Set email format to HTML
    $mail->Subject = 'Here is the subject';
    $mail->Body    = $message;

    $mail->send();
    echo 'Message has been sent';
} catch (Exception $e) {
    echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
}}

else { 
    echo "Message non envoye";

}

Ce que j'obtiens

J'ai bien le message "message has been send" mais je ne reçois rien dans ma boite aux lettres.
J'ai testé avec une boite Outlook et une boite Gmail.
Dans les deux cas ( aprés de nombreuses erreurs et de recherches sur le net ), j'ai bien "message ahs been send" mais aucun message sur les boites ( ni dans les spams )

Si quelqu'un a déjà ce problème et a la solution, je suis preneur.

Merci d'avance.

PS : Si ça peut aider je rajoute le log en ajoutant l'option mail SMTPDebug = 2 dans envoi.php

2018-12-18 23:02:01 SERVER -> CLIENT: 220 LO2P265CA0470.outlook.office365.com Microsoft ESMTP MAIL Service ready at Tue, 18 Dec 2018 23:02:00 +0000
2018-12-18 23:02:01 CLIENT -> SERVER: EHLO 127.0.0.1
2018-12-18 23:02:01 SERVER -> CLIENT: 250-LO2P265CA0470.outlook.office365.com Hello [81.66.9.119]250-SIZE 157286400250-PIPELINING250-DSN250-ENHANCEDSTATUSCODES250-STARTTLS250-8BITMIME250 SMTPUTF8
2018-12-18 23:02:01 CLIENT -> SERVER: STARTTLS
2018-12-18 23:02:01 SERVER -> CLIENT: 220 2.0.0 SMTP server ready
2018-12-18 23:02:01 CLIENT -> SERVER: EHLO 127.0.0.1
2018-12-18 23:02:01 SERVER -> CLIENT: 250-LO2P265CA0470.outlook.office365.com Hello [81.66.9.119]250-SIZE 157286400250-PIPELINING250-DSN250-ENHANCEDSTATUSCODES250-AUTH LOGIN XOAUTH2250-8BITMIME250 SMTPUTF8
2018-12-18 23:02:01 CLIENT -> SERVER: AUTH LOGIN
2018-12-18 23:02:01 SERVER -> CLIENT: 334 VXNlcm5hbWU6
2018-12-18 23:02:01 CLIENT -> SERVER: <credentials hidden>
2018-12-18 23:02:01 SERVER -> CLIENT: 334 UGFzc3dvcmQ6
2018-12-18 23:02:01 CLIENT -> SERVER: <credentials hidden>
2018-12-18 23:02:02 SERVER -> CLIENT: 235 2.7.0 Authentication successful
2018-12-18 23:02:02 CLIENT -> SERVER: MAIL FROM:<******@hotmail.fr>
2018-12-18 23:02:02 SERVER -> CLIENT: 250 2.1.0 Sender OK
2018-12-18 23:02:02 CLIENT -> SERVER: RCPT TO:<info@********.com>
2018-12-18 23:02:02 SERVER -> CLIENT: 250 2.1.5 Recipient OK
2018-12-18 23:02:02 CLIENT -> SERVER: DATA
2018-12-18 23:02:02 SERVER -> CLIENT: 354 Start mail input; end with <CRLF>.<CRLF>
2018-12-18 23:02:02 CLIENT -> SERVER: Date: Wed, 19 Dec 2018 00:02:01 +0100
2018-12-18 23:02:02 CLIENT -> SERVER: From: *****@hotmail.fr
2018-12-18 23:02:02 CLIENT -> SERVER: Cc: info@*******.com
2018-12-18 23:02:02 CLIENT -> SERVER: Reply-To: Information <info@*******.com>
2018-12-18 23:02:02 CLIENT -> SERVER: Subject: Here is the subject
2018-12-18 23:02:02 CLIENT -> SERVER: Message-ID: <xPJ0erQ93aVsW0bxreUAIGf2LVYOfmMEWVb9ZmHNc@127.0.0.1>
2018-12-18 23:02:02 CLIENT -> SERVER: X-Mailer: PHPMailer 6.0.6 (https://github.com/PHPMailer/PHPMailer)
2018-12-18 23:02:02 CLIENT -> SERVER: MIME-Version: 1.0
2018-12-18 23:02:02 CLIENT -> SERVER: Content-Type: text/html; charset=iso-8859-1
2018-12-18 23:02:02 CLIENT -> SERVER: 
2018-12-18 23:02:02 CLIENT -> SERVER: bcxbxc
2018-12-18 23:02:02 CLIENT -> SERVER: 
2018-12-18 23:02:02 CLIENT -> SERVER: .
2018-12-18 23:02:02 SERVER -> CLIENT: 250 2.0.0 OK <DB6PR1001MB11734B9114EDBB2BC9C8E50EE6BD0@DB6PR1001MB1173.EURPRD10.PROD.OUTLOOK.COM> [Hostname=DB6PR1001MB1173.EURPRD10.PROD.OUTLOOK.COM]
2018-12-18 23:02:02 CLIENT -> SERVER: QUIT
2018-12-18 23:02:02 SERVER -> CLIENT: 221 2.0.0 Service closing transmission channel
Message has been sent

Aucune réponse