I don’t know where y’all are accepting patches for this project, so I’ll just describe the fix.
line 1536
$result=mail('', $subject,'', $headers);
Each of the variables in the mail function mean something.
mail($emailTo, $subject, $body, $headers);
Because the first is left blank and To: header is created in line 1528, you end up with two "To" fields. The first is empty. This may mess up some clients where the recipient believes they are a bcc instead of the intended recipient.
The third variable, $body, is the body. Concatenating the body onto the end of the headers creates errors in multipart messages for some clients. Headers are headers. Body is Body. Resulting code should look like:
function sendNewsletterMail ($emails,$emailFrom,$newsletterId,$subject) {
global $modx;
$html = sendHTML($newsletterId);
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";
$body .= $send_html . "\n";
$result=mail($email, $subject, $body, $headers);
}
return $result;
}