1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-02 20:57:26 +02:00

Fixes altBody mailing issue.

This commit is contained in:
Cameron
2015-05-21 15:51:37 -07:00
parent e28997f420
commit dd08c0f078
3 changed files with 96 additions and 38 deletions

View File

@@ -109,7 +109,12 @@ class e107Bounce
{ {
if($errors = $this->setUser_Bounced($e107_userid)) if($errors = $this->setUser_Bounced($e107_userid))
{ {
// $message .= print_a($errors,true); if($this->debug)
{
echo "<h3>Errors</h3>";
print_a($errors);
}
} }
} }
@@ -194,13 +199,18 @@ class e107Bounce
function setUser_Bounced($bounceString = '', $email='' ) function setUser_Bounced($bounceString = '', $email='' )
{ {
if(!$email && !$bounceString){ return; } if(!$email && !$bounceString)
{
return false;
}
// echo "Email bounced ID: ".$id_or_email; // echo "Email bounced ID: ".$id_or_email;
require_once(e_HANDLER.'mail_manager_class.php');
$mailManager = new e107MailManager(); $mailManager = e107::getBulkEmail();
$mailManager->controlDebug($this->debug);
if ($errors = $mailManager->markBounce($bounceString, $email)) if ($errors = $mailManager->markBounce($bounceString, $email))
{ {
return $errors; // Failure return $errors; // Failure
} }

View File

@@ -570,7 +570,7 @@ class e107Email extends PHPMailer
$this->MsgHTML($message); // Theoretically this should do everything, including handling of inline images. $this->MsgHTML($message); // Theoretically this should do everything, including handling of inline images.
} }
else else
{ // generate the plain text as the sole part of the email { // generate the plain text as the sole part of the email
@@ -781,8 +781,8 @@ class e107Email extends PHPMailer
if($this->debug) if($this->debug)
{ {
echo "<h4>e107Email::arraySet() - line ".__LINE__."</h4>"; // echo "<h4>e107Email::arraySet() - line ".__LINE__."</h4>";
print_a($tmpl); // print_a($tmpl);
} }
unset($eml['add_html_header']); // disable other headers when template is used. unset($eml['add_html_header']); // disable other headers when template is used.
@@ -865,8 +865,9 @@ class e107Email extends PHPMailer
if($this->debug) if($this->debug)
{ {
echo "<h4>e107Email::arraySet() - line ".__LINE__."</h4>"; // echo "<h4>e107Email::arraySet() - line ".__LINE__."</h4>";
print_a($eml); return 0;
// print_a($eml);
//$this->PreSend(); //$this->PreSend();
//$debugEml = $this->GetSentMIMEMessage(). //$debugEml = $this->GetSentMIMEMessage().
//print_a($debugEml); //print_a($debugEml);
@@ -947,7 +948,7 @@ class e107Email extends PHPMailer
$result = TRUE; // Temporary 'success' flag $result = TRUE; // Temporary 'success' flag
$this->SendCount++; $this->SendCount++;
if (($this->logEnable == 0) || ($this->logEnable == 2)) if ($this->debug == false && (($this->logEnable == 0) || ($this->logEnable == 2)) )
{ {
// prevent user/script details being exposed in X-PHP-Script header // prevent user/script details being exposed in X-PHP-Script header
$oldphpself = $_SERVER['PHP_SELF']; $oldphpself = $_SERVER['PHP_SELF'];
@@ -969,8 +970,11 @@ class e107Email extends PHPMailer
} }
else else
{ // Debug { // Debug
$result = TRUE; $result = true;
//print_a($this); // echo "<h2>SendEmail()->Body</h2>";
// print_a($this->Body);
// echo "<h2>SendEmail()->AltBody</h2>";
// print_a($this->AltBody);
if (($this->logEnable == 3) && (($this->SendCount % 7) == 4)) $result = FALSE; // Fail one email in 7 for testing if (($this->logEnable == 3) && (($this->SendCount % 7) == 4)) $result = FALSE; // Fail one email in 7 for testing
} }
@@ -1015,6 +1019,10 @@ class e107Email extends PHPMailer
} }
function setDebug($val)
{
$this->debug = $val;
}
/** /**
* Called after a bulk mailing completed, to tidy up nicely * Called after a bulk mailing completed, to tidy up nicely
@@ -1126,18 +1134,30 @@ class e107Email extends PHPMailer
$this->IsHTML(true); $this->IsHTML(true);
$this->Body = $message; $this->Body = $message;
//print_a($message); //print_a($message);
$textMsg = str_replace(array('<br />', '<br>'), "\n", $message); // Modified to make sure newlines carried through $textMsg = str_replace("\n", "", $message);
$textMsg = str_replace(array('<br />', '<br>'), "\n", $textMsg); // Modified to make sure newlines carried through
$textMsg = preg_replace('#^.*?<body.*?>#', '', $textMsg); // Knock off everything up to and including the body statement (if present) $textMsg = preg_replace('#^.*?<body.*?>#', '', $textMsg); // Knock off everything up to and including the body statement (if present)
$textMsg = preg_replace('#</body.*?>.*$#', '', $textMsg); // Knock off everything after and including the </body> (if present) $textMsg = preg_replace('#</body.*?>.*$#', '', $textMsg); // Knock off everything after and including the </body> (if present)
$textMsg = trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/s','',$textMsg))); $textMsg = trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/s','',$textMsg)));
if (!empty($textMsg) && empty($this->AltBody))
if($this->debug)
{
echo "<h2>".__METHOD__.' $textMsg<small> Line: '.__LINE__.'</small></h2>';
print_a($textMsg);
}
if(!empty($textMsg)) // Always set it, even if AltBody is empty.
{ {
$this->AltBody = html_entity_decode($textMsg); $this->AltBody = html_entity_decode($textMsg);
} }
if (empty($this->AltBody))
if(empty($this->AltBody))
{ {
$this->AltBody = 'To view this email message, enable HTML!' . "\n\n"; $this->AltBody = 'To view this email message, enable HTML!' . "\n\n";
} }
} }
} // End of e107Mailer class } // End of e107Mailer class

View File

@@ -500,13 +500,13 @@ class e107MailManager
*/ */
protected function checkDB($which = 1) protected function checkDB($which = 1)
{ {
if (($which == 1) && ($this->db == NULL)) if (($which == 1) && ($this->db == null))
{ {
$this->db = new db; $this->db = e107::getDb('mail1');
} }
if (($which == 2) && ($this->db2 == NULL)) if (($which == 2) && ($this->db2 == null))
{ {
$this->db2 = new db; $this->db2 = e107::getDb('mail2');;
} }
} }
@@ -621,17 +621,17 @@ class e107MailManager
{ {
if (!$this->queryActive) if (!$this->queryActive)
{ {
return FALSE; return false;
} }
if ($result = $this->db->db_Fetch(MYSQL_ASSOC)) if ($result = $this->db->fetch(MYSQL_ASSOC))
{ {
$this->queryActive--; $this->queryActive--;
return $this->dbToBoth($result); return $this->dbToBoth($result);
} }
else else
{ {
$this->queryActive = FALSE; // Make sure no further attempts to read emails $this->queryActive = false; // Make sure no further attempts to read emails
return FALSE; return false;
} }
} }
@@ -714,7 +714,8 @@ class e107MailManager
} }
$this->currentTextBody = $email['mail_body_alt']; // May be null $this->currentTextBody = $email['mail_body_alt']; // May be null
} }
$mailToSend = $this->makeEmailBlock($email); // Substitute mail-specific variables, attachments etc $mailToSend = $this->makeEmailBlock($email); // Substitute mail-specific variables, attachments etc
@@ -729,13 +730,30 @@ class e107MailManager
print_a($preview); print_a($preview);
$logName = "mailout_simulation_".$email['mail_source_id']; $logName = "mailout_simulation_".$email['mail_source_id'];
e107::getLog()->addDebug("Sending Email to <".$email['mail_recipient_name']."> ".$email['mail_recipient_email'])->toFile($logName,'Mailout Simulation Log',true); e107::getLog()->addDebug("Sending Email to <".$email['mail_recipient_name']."> ".$email['mail_recipient_email'])->toFile($logName,'Mailout Simulation Log',true);
$result = true; $result = true;
$this->mailer->setDebug(true);
echo "<h2>SendEmail()->Body</h2>";
print_a($this->mailer->Body);
echo "<h2>SendEmail()->AltBody</h2>";
print_a($this->mailer->AltBody);
echo "<h1>_________________________________________________________________________</h1>";
return;
} }
else
// else
{ {
$result = $this->mailer->sendEmail($email['mail_recipient_email'], $email['mail_recipient_name'], $mailToSend, TRUE); $result = $this->mailer->sendEmail($email['mail_recipient_email'], $email['mail_recipient_name'], $mailToSend, TRUE);
} }
if($this->debugMode)
{
return true;
}
// Try and send // Try and send
@@ -973,7 +991,7 @@ class e107MailManager
$result = array_merge($result, $email['mail_overrides']); $result = array_merge($result, $email['mail_overrides']);
} }
$title = "<h4>".__METHOD__." Line: ".__LINE__."</h4>"; // $title = "<h4>".__METHOD__." Line: ".__LINE__."</h4>";
// e107::getAdminLog()->addDebug($title.print_a($email,true),true); // e107::getAdminLog()->addDebug($title.print_a($email,true),true);
if(!empty($email['mail_media'])) if(!empty($email['mail_media']))
@@ -981,7 +999,7 @@ class e107MailManager
$result['media'] = $email['mail_media']; $result['media'] = $email['mail_media'];
} }
$title2 = "<h4>".__METHOD__." Line: ".__LINE__."</h4>"; // $title2 = "<h4>".__METHOD__." Line: ".__LINE__."</h4>";
// e107::getAdminLog()->addDebug($title2.print_a($result,true),true); // e107::getAdminLog()->addDebug($title2.print_a($result,true),true);
$result['shortcodes']['MAILREF'] = $email['mail_source_id']; $result['shortcodes']['MAILREF'] = $email['mail_source_id'];
@@ -1368,11 +1386,14 @@ class e107MailManager
$bounceInfo = array('mail_bounce_string' => $bounceString, 'mail_recipient_email' => $emailAddress); // Ready for event data $bounceInfo = array('mail_bounce_string' => $bounceString, 'mail_recipient_email' => $emailAddress); // Ready for event data
$errors = array(); // Log all errors, at least until proven $errors = array(); // Log all errors, at least until proven
$vals = explode('/', $bounceString); // Should get one or four fields $vals = explode('/', $bounceString); // Should get one or four fields
// echo "<h4>Bounce String</h4>"; if($this->debugMode)
// print_a($bounceString); {
// echo "<h4>Vals</h4>"; echo "<h4>Bounce String</h4>";
// print_a($vals); print_a($bounceString);
echo "<h4>Vals</h4>";
print_a($vals);
}
if (!is_numeric($vals[0])) // Email recipient user id number (may be zero) if (!is_numeric($vals[0])) // Email recipient user id number (may be zero)
{ {
@@ -1448,13 +1469,13 @@ class e107MailManager
if(!$this->db->update('mail_content', '`mail_bounce_count` = `mail_bounce_count` + 1 WHERE `mail_source_id` = '.$vals[1])) if(!$this->db->update('mail_content', '`mail_bounce_count` = `mail_bounce_count` + 1 WHERE `mail_source_id` = '.$vals[1]))
{ {
e107::getAdminLog()->add('Unable to increment bounce-count on mail_source_id='.$vals[1],$bounceInfo, E_LOG_FATAL, 'BOUNCE',LOG_TO_ROLLING); e107::getAdminLog()->add('Unable to increment bounce-count on mail_source_id='.$vals[1],$bounceInfo, E_LOG_FATAL, 'BOUNCE', LOG_TO_ROLLING);
} }
if(!$this->db->update('mail_recipients', '`mail_status` = '.MAIL_STATUS_BOUNCED.' WHERE `mail_target_id` = '.$vals[2])) if(!$this->db->update('mail_recipients', '`mail_status` = '.MAIL_STATUS_BOUNCED.' WHERE `mail_target_id` = '.$vals[2]))
{ {
e107::getAdminLog()->add('Unable to update recipient mail_status to bounce on mail_target_id = '.$vals[2],$bounceInfo, E_LOG_FATAL, 'BOUNCE',LOG_TO_ROLLING); e107::getAdminLog()->add('Unable to update recipient mail_status to bounce on mail_target_id = '.$vals[2],$bounceInfo, E_LOG_FATAL, 'BOUNCE', LOG_TO_ROLLING);
} }
$addons = array_keys($row['mail_selectors']); // trigger e_mailout.php addons. 'bounce' method. $addons = array_keys($row['mail_selectors']); // trigger e_mailout.php addons. 'bounce' method.
@@ -1503,12 +1524,19 @@ class e107MailManager
$errors[] = $err; $errors[] = $err;
} }
} }
if (!empty($errors)) if (!empty($errors))
{ {
$logErrors =$bounceInfo;
$logErrors['user_id'] = $uid;
$logErrors['mailshot'] = $vals[1];
$logErrors['mailshot_recipient'] = $vals[2];
$logErrors['errors'] = $errors;
$logErrors['email'] = $emailAddress;
$logErrors['bounceString'] = $bounceString;
$logString = $bounceString.' ('.$emailAddress.')[!br!]'.implode('[!br!]',$errors).implode('[!br!]',$bounceInfo); $logString = $bounceString.' ('.$emailAddress.')[!br!]'.implode('[!br!]',$errors).implode('[!br!]',$bounceInfo);
// e107::getAdminLog()->e_log_event(10,-1,'BOUNCE','Bounce receive error',$logString, FALSE,LOG_TO_ROLLING); // e107::getAdminLog()->e_log_event(10,-1,'BOUNCE','Bounce receive error',$logString, FALSE,LOG_TO_ROLLING);
e107::getAdminLog()->add('Bounce receive error',$logString, E_LOG_WARNING, 'BOUNCE', LOG_TO_ROLLING); e107::getAdminLog()->add('Bounce receive error',$logErrors, E_LOG_WARNING, 'BOUNCE', LOG_TO_ROLLING);
return $errors; return $errors;
} }
else else