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 30 31 32 33 34 35
| class Mailer
{
public static function send(string $msg, string $subject): void
{
try {
$mail = new PHPMailer();
$mail->isHTML(true);
$mail->CharSet = "UTF-8";
//$mail->SMTPDebug = SMTP::DEBUG_SERVER; //Enable verbose debug output
//$mail->isSMTP(); //Send using SMTP à enlever si en ligne
$mail->Host = 'smtp.gmail.com'; //Set the SMTP server to send through
$mail->SMTPAuth = true; //Enable SMTP authentication
$mail->Username = 'xxx@gmail.com'; //SMTP username
$mail->Password = 'xxx'; //SMTP password
$mail->SMTPSecure = 'tls'; //Enable implicit TLS encryption
$mail->Port = 465;
$mail->From='xxx';
$mail->addAddress('xxx@gmail.com');
$mail->addReplyTo($_POST["email"]);
$mail->Subject = $subject;
$mail->Body = $msg;
if(!$mail->send()){ //Teste le code de la fonction
echo $mail->ErrorInfo; //Affiche le message d'erreur (ATTENTION:voir section 7)
}
$mail->smtpClose();
//echo "envoi mail on est ds le try";
unset($mail);
}
catch (Exception $e) {
die("<br><strong>Erreur : " . $e->getMessage() . "</strong></h4>");
}
}
} |
Partager