Skip to content

Instantly share code, notes, and snippets.

@tmdarty

tmdarty/testmail.php

Last active Oct 29, 2019
Embed
What would you like to do?
Tuto : Comment envoyer des mails en PHPMailer[Testmail.php]
<?
//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