Last active
October 29, 2019 13:04
-
-
Save tmdarty/cba24a0fce30ca6a080519830a14f7d2 to your computer and use it in GitHub Desktop.
Tuto : Comment envoyer des mails en PHPMailer[Testmail.php]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
//Inclure la classe PHPMailer | |
require "PHPMailer/PHPMailerAutoload.php"; | |
function smtpmailer($to, $from, $from_name, $subject, $body) | |
{ | |
$mail = new PHPMailer(); | |
$mail->IsSMTP(); | |
$mail->SMTPAuth = true; | |
$mail->SMTPSecure = 'ssl'; | |
$mail->Host = 'smtp.server.com'; | |
$mail->Port = 465; | |
$mail->Username = 'contact@votresite.com'; | |
$mail->Password = 'votre_mot_de_passe'; | |
$lien = 'votreducument.pdf'; | |
$mail->AddAttachment($path); | |
$mail->IsHTML(true); | |
$mail->From="contact@votresite.com"; | |
$mail->FromName=$from_name; | |
$mail->Sender=$from; | |
$mail->AddReplyTo($from, $from_name); | |
$mail->Subject = $subject; | |
$mail->Body = $body; | |
$mail->AddAddress($to); | |
if(!$mail->Send()) | |
{ | |
$error ="Erreur..."; | |
return $error; | |
} | |
else | |
{ | |
$error = "Merci. Votre message a été bien envoyé."; | |
return $error; | |
} | |
} | |
//Envoie du mail | |
$to = 'utilisateur@gmail.com' | |
$from = 'contact@votresite.com'; | |
$name = 'Le nom de votre site ou companie'; | |
$subj = 'Ceci est un message de test pour PHPMailer'; | |
$msg = 'Votre message ici'; | |
$error=smtpmailer($to,$from, $name ,$subj, $msg); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment