function sendNewsletterMail ($emails,$emailFrom,$newsletterId,$subject) {
global $modx;
$html = sendHTML($newsletterId);
require_once('controls/class.phpmailer.php');
$base_path = $modx->config['base_path'];
$tvs = $modx->getTemplateVarOutput('Attachment',$newsletterId);
$attachment = $base_path . $tvs['Attachment'];
foreach ($emails as $id => $datas) {
$email = $datas['val'];
$timestamp = $datas['timestamp'];
$MD5 = ControlMD5($email,$timestamp);
$link = 'http://'.$_SERVER['HTTP_HOST'].'/index.php?&id='.$modx->TXNewsletters['idPageUnsubscribe'].'&action=del&email='.$email.'&control='.$MD5;
$send_html = preg_replace('/\{link_unsubscribe\}/', $link, $html);
$headers = 'From: ' . $emailFrom . "\n";
$headers .= 'To: ' . $email . "\n";
$headers .= 'Return-Path: ' . $emailFrom . "\n";
$headers .= 'MIME-Version: 1.0' ."\n";
$headers .= 'Content-Type: text/html; charset=UTF-8' ."\n";
$headers .= 'Content-Transfer-Encoding: 8bit'. "\n\n";
$headers .= $send_html . "\n";
// $result=mail('', $subject,'', $headers);
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->IsHTML(true);
$mail->CharSet = 'UTF-8';
$mail->Host = "mail.yourdomain.com"; // SMTP server example
$mail->SMTPDebug = 0; // enables SMTP debug information (for testing)
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Port = 25; // set the SMTP port for the GMAIL server
$mail->Username = "unsername"; // SMTP account username example
$mail->Password = "password"; // SMTP account password example
$mail->From = $emailFrom;
$mail->FromName = 'arbitrary name/message';
$mail->Subject = $subject;
$mail->Body = $send_html;
$mail->AddAddress($email);
if($attachment != $base_path) {
$mail->AddAttachment($attachment);
}
if(!$mail->send())
echo $mail->ErrorInfo,'<br>';
$result=true;
}
return $result;
}
]]>