batch/library/framework/mail/sendMail.php

49 lines
1.2 KiB
PHP
Raw Normal View History

<?php
2013-06-19 09:45:13 +00:00
/**
*
* @param unknown $from
* @param unknown $to
* @param unknown $subject
* @param string $text
* @param string $html
* @param unknown $tabAttachedFiles
*/
function sendMail($from, $to, $subject, $text='', $html='', $tabAttachedFiles=array())
{
2013-06-19 09:45:13 +00:00
$to = preg_split("/[\s,;]+/", $to);
2013-06-19 09:45:13 +00:00
$mail = new Zend_Mail('ISO-8859-15');
$tr = new Zend_Mail_Transport_Smtp(SMTP_HOST, array('port'=>SMTP_PORT));
$mail->setDefaultTransport($tr);
$mail->setFrom($from);
if ( count($to) > 0 ) {
foreach ( $to as $item ) {
$mail->addTo($item);
}
}
$mail->setSubject($subject);
2013-06-19 09:45:13 +00:00
if ($text!='') {
$mail->setBodyText(mb_convert_encoding($text, 'ISO-8859-15', 'UTF-8'));
}
2013-06-19 09:45:13 +00:00
if ($html!='') {
$mail->setBodyHtml(mb_convert_encoding($html, 'ISO-8859-15', 'UTF-8'));
}
2013-06-19 09:45:13 +00:00
if ( count($tabAttachedFiles) > 0 ) {
foreach ($tabAttachedFiles as $file) {
$at = new Zend_Mime_Part( file_get_contents( $file ) );
$mail->addAttachment($at);
}
}
2013-06-19 09:45:13 +00:00
try {
$mail->send();
} catch (Zend_Mail_Transport_Exception $e) {
file_put_contents(LOG_PATH.'/sendMailError.log',date('Y-m-d H:i:s')." - ".$e->getMessage().PHP_EOL, FILE_APPEND);
2013-06-19 09:45:13 +00:00
}
}
?>