include("phpmailer/class.phpmailer.php");
include("phpmailer/class.smtp.php"); // note, this is optional - gets called from main class if not already loaded
date_default_timezone_set("Europe/Zurich");
$mail = new PHPMailer();
$body = 'test d\'un msg envoyer par la class phpmailer';
$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
$mail->Username = "nom.prenom"; // GMAIL username
$mail->Password = "mon gmail mot de pass"; // GMAIL password
$mail->From = "[email protected]";
$mail->FromName = "nomPrenom";
$mail->Subject = "Nouveau msg";
$mail->AltBody = "This is the body when user views in plain text format"; //Text Body
$mail->WordWrap = 50; // set word wrap
$mail->MsgHTML($body);
$mail->AddReplyTo("[email protected]","JP");
$mail->AddAddress("[email protected]","XXX");
$mail->IsHTML(true); // send as HTML
if(!$mail->Send()) {
$msg = '<span style="color:red;">Erreur : Le message n\'a pu être envoyé, merci de reéssayer plus tard</span> ' . $mail->ErrorInfo;
} else {
$msg = '<span style="color:green;">Votre message a bien été envoyé, on vous répondera le plutôt possible,<br/> Merci pour votre confiance</span>';
}
et j'ai cette erreur Fatal error: Call to undefined method PHPMailer::MsgHTML() in line 91 qui correspond a $mail->MsgHTML($body);en fait ton second include n'est pas indispensable et le fait de le mettre génère des erreurs car la classe PHPMailer l’inclut de facto lors de son instanciation.Après, le reste du code est bon.oui alors j'ai vu sur internet est on me conseil d'utiliser la class phpmailer j'ai donc téléchager la class, et j'ai suivi un tuto et voici mon code
et j'ai cette erreur Fatal error: Call to undefined method PHPMailer::MsgHTML() in line 91 qui correspond a $mail->MsgHTML($body);include("phpmailer/class.phpmailer.php"); //include("phpmailer/class.smtp.php"); // note, this is optional - gets called from main class if not already loaded date_default_timezone_set("Europe/Zurich"); $mail = new PHPMailer(); }
<?php
include("../PHPMailer/class.phpmailer.php");
date_default_timezone_set("Europe/Paris");
try {
$mail = new PHPMailer(true);
$mail->CharSet = 'utf-8';
// debug
$mail->SMTPDebug = 2;
$mail->Debugoutput = 'html';
$body = 'test d\'un msg envoyer par la class phpmailer';
$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
$mail->Username = "****@gmail.com"; // GMAIL username
$mail->Password = "****"; // GMAIL password
$mail->From = "***@gmail.com";
$mail->FromName = "nomPrenom";
$mail->Subject = "Message test phpmailer";
$mail->AltBody = "This is the body when user views in plain text format"; //Text Body
$mail->WordWrap = 50; // set word wrap
$mail->MsgHTML($body);
$mail->AddReplyTo("***@gmail.com", "JP");
$mail->AddAddress("****@gmail.com", "Moogli");
$mail->IsHTML(true); // send as HTML
if (!$mail->Send()) {
$msg = '<span style="color:red;">Erreur : Le message n\'a pu être envoyé, merci de reéssayer plus tard</span> ' . $mail->ErrorInfo;
} else {
$msg = '<span style="color:green;">Votre message a bien été envoyé, on vous répondera le plutôt possible,<br/> Merci pour votre confiance</span>';
}
echo $msg;
} catch (Exception $e) {
echo $e->getMessage() . '<br />' . $e->getTraceAsString();
}
j'ai activé le debug afin de pouvoir suivre ce qui se passe cela permet de voir la où il y a un soucis
il faut désactiver le debug en le mettant à 0:J'ai téléchargé la version de lien que tu m'as passé et sa marche![]()
par contre j'ai une liste des lignes de genre SMTP -> FROM ...... des information sur le mail je pense comment je peux supprimer l'affichage de ces infos ?
$mail->SMTPDebug = 0;
$mail->Username = "[email protected]"; // GMAIL username
$mail->Password = "mon gmail mot de pass"; // GMAIL password
$mail->From = "[email protected]";
Bon développement