2012-01-13 13:35:11 +00:00

103 lines
3.9 KiB
PHP

<?
function sendMail($from, $to, $subject, $text='', $html='', /*$priority='high', $tabImgFiles=array(), */$tabAttachedFiles=array())
{
//return true;
$to=preg_split("/[\s,;]+/", $to);
//die(print_r($to));
require_once('Mail.php');
require_once('Mail/mime.php');
$headers=array( 'From'=>$from,
'To'=>$to,
'Subject'=>$subject,
// 'Reply-To'=>$from,
// 'Return-Path'=>$from,
'Content-Transfer-Encoding'=>'8bit',
'MIME-Version'=>'1.0',
'Date'=>date('D, d M Y H:i:s O'),
'Message-ID'=>'<'.md5(date('YmdHis')).'@mail.scores-decisions.com>',
'X-Priority'=>3,
'X-Mailer'=>'PHP v'.phpversion(),
);
/*
# Boundry for marking the split & Multitype Headers
$mime_boundary=md5(time());
$headers .= ''.$eol;
$headers .= "Content-Type: multipart/related; boundary=\"".$mime_boundary."\"".$eol;
$msg = "";
*/
$mime = new Mail_mime();
$footer="";/*
_______________________________________________________________________
Ce message et toutes les pièces jointes (ci-après le \"message\") sont établis a l'intention exclusive de ses destinataires.Si vous recevez ce message par erreur, merci de le détruire et d'en avertir immédiatement l'expéditeur par e-mail. Toute utilisation de ce message non conforme a sa destination, toute diffusion ou toute publication, totale ou partielle, est interdite, sauf autorisation expresse. Les communications sur Internet n'étant pas sécurisées, SCORES & DECISIONS S.A.S. informe qu'elle ne peut accepter aucune responsabilite quant au contenu de ce message.
This mail message and attachments (the \"message\") are solely intended for the addressees. It is confidential in nature . If you receive this message in error, please delete it and immediately notify the sender by e-mail. Any use other than its intended purpose, dissemination or disclosure, either whole or partial, is prohibited except if formal approval is granted. As communication on the Internet is not secure, SCORES & DECISIONS S.A.S. does not accept responsability for the content of this message.
";*/
if ($text<>'') $mime->setTXTBody($text.$footer);
if ($html<>'') $mime->setHTMLBody($html);
foreach ($tabAttachedFiles as $file)
$mime->addAttachment($file);
//do not ever try to call these lines in reverse order
$body = $mime->get();
$headers = $mime->headers($headers);
$params=array( 'host'=>'smtpauth.online.net', // SMTP_HOST
'port'=>25, //SMTP_PORT,
);
$params=array( 'host'=>SMTP_HOST,
'port'=>SMTP_PORT,
//'debug'=>true,
//'persist'=>true,
);
if (SMTP_USER=='' && SMTP_PASS=='')
$params['auth'] = false;
else {
$params['username'] = SMTP_USER;
$params['password'] = SMTP_PASS;
}/*
$params['auth'] = true;
$params['username'] = 'buzuk@scores-decisions.com';
$params['password'] = 'catsysyo92';
*/
$nbEssais=0;
while (1) {
// Create the mail object using the Mail::factory method
$mail_object = Mail::factory('smtp', $params);
// Trying to send the mail
$send = $mail_object->send($to, $headers, $body);
$nbEssais++;
if (PEAR::isError($send)) {
/** @todo tester les différents codes erreur **/
echo date('Y-m-d H:i:s'). " sendMail.php - essai #$nbEssais : ".$send->getMessage().EOL;
if (preg_match('/too many connections|421/i', $send->getMessage()))
sleep($nbEssais);
else {
$strTo=implode(';', $to);
file_put_contents( LOG_PATH.'/sendMailError.log',
date('Y-m-d H:i:s')."\t#$nbEssais\t$strTo\t".$send->getMessage().EOL,
FILE_APPEND);
break;
}
} else {
/** Si nous sommes en mode CLI, alors on fait en sorte de ne pas atteindre
la limite des 25 mails par minute (ramené à 100 / minute)
**/
if (MODE_EXEC==MODE_CLI) usleep(500000);
break;
}
}
return true;
}
?>