voila code php :
<?php
require_once('class.phpmailer.php');
require_once('class.smtp.php');
//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded
$mail = new PHPMailer();
$body = "welcome";
$mail->IsSMTP();
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 465; // set the SMTP port for the GMAIL server
$mail->Username = "***********@gmail.com"; // GMAIL username
$mail->Password = "***********"; // GMAIL password
$mail->AddReplyTo("***********@gmail.c… ");
$mail->From = "***********@gmail.com";
$mail->FromName = "salim(S@) ";
$mail->Subject = "test de gmail PHP ";
//$mail->Body = "Hi,<br>This is the HTML BODY<br>"; //HTML Body
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->WordWrap = 50; // set word wrap
$mail->AddAddress("*************@gmail…
$mail->Body = "test de PHP gmail";
$mail->IsHTML(true); // send as HTML
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>
Copyright © 2024 1QUIZZ.COM - All rights reserved.
Answers & Comments
Verified answer
le message est assez explicite: tu ne peux pas te connecter au serveur smtp de google.
alors, plusieurs choses a vérifier:
* la machine sur laquelle tourne ton serveur php arrive t elle à joindre le serveur smtp en question? (ping) si non, le probleme vient de la
* il faut vérifier l'ensemble des champs servant à la connexion. ca fait un bail que je n'ai pas fait de php, je te fait confiance sur le nom des champs (mais vérifie quand même).
là, j'essayerai l'autre port indiqué dans la page d'aide à la config de google pour leur service mail:
"Also, if you're having trouble sending mail but you've confirmed that encryption is active for SMTP in your mail client, try to configure your SMTP server on a different port: 465 or 587. "