55 lines
1.9 KiB
PHP
55 lines
1.9 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Envoi un mail suivant la configuration
|
|
* @param string $sujet
|
|
* @param string $message
|
|
* @param array $from
|
|
* Emetteur définit par un tableau (email => email , name => name)
|
|
* @param array $to
|
|
* Recepteur définit par un tableau (idem $from)
|
|
* @param array $cc
|
|
*/
|
|
function sendMail($sujet, $message, $from, $to, $cc = array())
|
|
{
|
|
require_once 'phpmailer/class.phpmailer.php';
|
|
$mail = new PHPMailer(true);
|
|
// Choix de la méthode d'envoi
|
|
if (MAIL_METHOD == 'sendmail') {
|
|
$mail->IsSendmail();
|
|
} else if (MAIL_METHOD == 'smtp') {
|
|
$mail->IsSMTP();
|
|
$mail->SMTPDebug = 0; // 0, 1, 2
|
|
$mail->Host = MAIL_SMTPHOST;
|
|
$mail->Port = defined('MAIL_SMTPPORT') ? MAIL_SMTPPORT : 25;
|
|
$mail->SMTPAuth = defined('MAIL_SMTPAUTH') ? MAIL_SMTPAUTH : false;
|
|
$mail->Username = defined('MAIL_SMTPUSER') ? MAIL_SMTPUSER : '';
|
|
$mail->Password = defined('MAIL_SMTPPASS') ? MAIL_SMTPPASS : '';
|
|
}
|
|
// Spécification du charset
|
|
$mail->CharSet = defined('CHARSET')? CHARSET : 'utf-8';
|
|
// Envoi du mail
|
|
try {
|
|
$body = $message;
|
|
//$body = preg_replace('/\\\/', '', $body);
|
|
$mail->MessageID = '<'.md5(date('YmdHis')).
|
|
'@mail.scores-decisions.com>';
|
|
$mail->AddReplyTo($from['email'], $from['name']);
|
|
$mail->SetFrom($from['email'], $from['name']);
|
|
foreach ($to as $info) {
|
|
$mail->AddAddress($info['email'], $info['name']);
|
|
}
|
|
$mail->Subject = $sujet;
|
|
$mail->MsgHTML($body);
|
|
$mail->Send();
|
|
return true;
|
|
} catch (phpmailerException $e) {
|
|
// Ecriture des erreurs dans un fichier (sujet, to)
|
|
file_put_contents(PATH_DATA.'/log/mailerror.log',
|
|
$e->errorMessage().' '.$to.' '.$sujet,
|
|
FILE_APPEND);
|
|
return false;
|
|
}
|
|
}
|
|
|