2

I had some contacts who complain of not receiving mailings. In communication preferences, email formats were 'both' for all contacts. Quite by chance, I went to look in the log file, where there were messages:

CiviMail will not send an empty email body, Skipping: xxxxx

After having researched this message in the php code, I analyzed CRM/Mailing/BAO/Mailing.php and saw that the body of the message is deleted if $contact['preferred_mail_format'] is neither Both, Text or HTML.

I went in the database, and for all contacts who did not receive the mailings, I've seen that the preferred_mail_format column contained NULL.

I have corrected by hand and all mails are gone.

I wonder if we should not: - Or, if preferred_mail_format is neither Both, Text or HTML, put a mail contains in a default format (Text, Html,?) - Or, when calculating the number of recipients (in the mailing of the editorial page), display a warning indicating the potential problems.

Regards.

1

We fixed this quite old behaviour by hacking CRM/Mailing/BAO/Mailing.php around line 1295 by overriding:

if ($text && ($test || $contact['preferred_mail_format'] == 'Text' ||
    $contact['preferred_mail_format'] == 'Both' ||
    ($contact['preferred_mail_format'] == 'HTML' && !array_key_exists('html', $pEmails))
  )
) {
  $textBody = implode('', $text);
  if ($useSmarty) {
    $textBody = $smarty->fetch("string:$textBody");
  }
  $mailParams['text'] = $textBody;
}

if ($html && ($test || ($contact['preferred_mail_format'] == 'HTML' ||
      $contact['preferred_mail_format'] == 'Both'
    ))
) {
  $htmlBody = implode('', $html);
  if ($useSmarty) {
    $htmlBody = $smarty->fetch("string:$htmlBody");
  }
  $mailParams['html'] = $htmlBody;
}

with:

$pmf = isset($contact['preferred_mail_format']) ?   $contact['preferred_mail_format'] : 'Both';
if ($pmf != "Both" && $pmf != "Text" && $pmf != "HTML") {
    $pmf = "Both";
}
if ($text && ($test || $pmf == 'Text' || $pmf == 'Both' ||
        ($pmf == 'HTML' && !array_key_exists('html', $pEmails))
)
) {
    $textBody = implode('', $text);
    if ($useSmarty) {
        $textBody = $smarty->fetch("string:$textBody");
    }
    $mailParams['text'] = $textBody;
}

if ($html && ($test || ($pmf == 'HTML' || $pmf == 'Both' ))) {
    $htmlBody = implode('', $html);
    if ($useSmarty) {
        $htmlBody = $smarty->fetch("string:$htmlBody");
    }
    $mailParams['html'] = $htmlBody;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.