Bonjour à tous,

J'ai essayé beaucoup de solutions proposées pour exploiter via PhpMailer le SMTP de Google, rien de fonctionne, je tourne en rond :
Google n'autorise plus l'accès aux applications moins sécurisées, j'ai donc créé une authentification 2 facteurs, un mot de passe dédié pour les applications externes (https://myaccount.google.com/apppasswords).
J'ai toujours la même erreur :
2025-01-28 11:45:45 CLIENT -> SERVER: EHLO www.monsite.fr
2025-01-28 11:45:45 CLIENT -> SERVER: STARTTLS
2025-01-28 11:45:45 CLIENT -> SERVER: EHLO www.monsite.fr
2025-01-28 11:45:45 CLIENT -> SERVER: AUTH LOGIN
2025-01-28 11:45:45 CLIENT -> SERVER: [credentials hidden]
2025-01-28 11:45:45 CLIENT -> SERVER: [credentials hidden]
2025-01-28 11:45:45 SMTP ERROR: Password command failed: 535-5.7.8 Username and Password not accepted. For more information, go to535 5.7.8 https://support.google.com/mail/?p=BadCredentials 5b1f17b1804b1-438bd4857cesm164048125e9.13 - gsmtp
SMTP Error: Could not authenticate.
Mon code réduit au plus simple :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'PHPMailer-master/src/Exception.php';
require 'PHPMailer-master/src/PHPMailer.php';
require 'PHPMailer-master/src/SMTP.php';
 
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Mailer = "smtp";
$mail->SMTPDebug  = 1;  
$mail->SMTPAuth   = TRUE;
$mail->SMTPSecure = "tls";
$mail->Port       = 587;
$mail->Host       = "smtp.gmail.com";
$mail->Username   = "noreply@monsite.com";
$mail->Password   = "monpasse";
$mail->IsHTML(true);
$mail->AddAddress("noreply@monsite.com", "PMO");
$mail->SetFrom("noreply@monsite.com", "PMO");
$mail->AddReplyTo("noreply@monsite.com", "PMO");
$mail->Subject = "Test  Mailer";
$content = "<b>Test PHP mailer.</b>";
$mail->MsgHTML($content); 
if(!$mail->Send()) {
  echo "KO";
  var_dump($mail);
} else {
  echo "OK";
}
Quelqu'un aurait il trouvé la solution ?
Merci à vous