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
|
function sendMail($sujet, $message, $destinataires, $expediteur) {
// Instantiation and passing `true` enables exceptions
$mail = new PHPMailer(true);
try {
//Server settings
$mail->SMTPDebug = 0; // Enable verbose debug output
$mail->CharSet = 'UTF-8';
$mail->isSMTP(); // Send using SMTP
$mail->Host = 'blablaHost'; // Set the SMTP server to send through
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'contact@monsite.fr'; // SMTP username
$mail->Password = 'rowanmayfaire'; // SMTP password
$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS; // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` encouraged
$mail->Port = 465; // TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` above
//Recipients
$mail->setFrom('contact@monsite.fr');
$mail->addAddress($destinataires); // Add a recipient
$mail->addReplyTo($expediteur); // Pour ajouter l'adresse à laquelle répondre (en général celle de la personne ayant rempli le formulaire)
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = $sujet;
$mail->Body = $message ;
$mail->send();
} catch (Exception $e) {
echo "Message n'a pas pu être envoyé : {$mail->ErrorInfo}";
}
} |
Partager