51 lines
1.4 KiB
PHP

<?php
/**
*
* @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())
{
$to = preg_split("/[\s,;]+/", $to);
$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);
if ($text!='') {
$mail->setBodyText(mb_convert_encoding($text, 'ISO-8859-15', 'UTF-8'));
}
if ($html!='') {
$mail->setBodyHtml(mb_convert_encoding($html, 'ISO-8859-15', 'UTF-8'));
}
if ( count($tabAttachedFiles) > 0 ) {
foreach ($tabAttachedFiles as $file) {
$at = new Zend_Mime_Part( file_get_contents( $file ) );
$mail->addAttachment($at);
}
}
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);
} catch (Zend_Mail_Protocol_Exception $e) {
file_put_contents(LOG_PATH.'/sendMailError.log',date('Y-m-d H:i:s')." - ".$e->getMessage().PHP_EOL, FILE_APPEND);
}
}
?>