2010-03-01 11:29:38 +00:00

58 lines
1.4 KiB
PHP

<?php
/*
* Suivant la configuration utiliser le smtp
* ou utilisend sendmail
* phpmailer ou commande mail
*
*/
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();
}
elseif(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 = CHARSET;
//Envoi du mail
try
{
$body = $message;
$body = eregi_replace("[\]",'',$body);
$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.'/mailerror.log',
$e->errorMessage().' '.$to.' '.$sujet,
FILE_APPEND
);
return false;
}
}