Answers.Body: <p>We fixed this quite old behaviour by hacking CRM/Mailing/BAO/Mailing.php around line 1295 by overriding:</p>
  
  <pre><code>if ($text &amp;&amp; ($test || $contact['preferred_mail_format'] == 'Text' ||
      $contact['preferred_mail_format'] == 'Both' ||
      ($contact['preferred_mail_format'] == 'HTML' &amp;&amp; !array_key_exists('html', $pEmails))
    )
  ) {
    $textBody = implode('', $text);
    if ($useSmarty) {
      $textBody = $smarty-&gt;fetch("string:$textBody");
    }
    $mailParams['text'] = $textBody;
  }
  
  if ($html &amp;&amp; ($test || ($contact['preferred_mail_format'] == 'HTML' ||
        $contact['preferred_mail_format'] == 'Both'
      ))
  ) {
    $htmlBody = implode('', $html);
    if ($useSmarty) {
      $htmlBody = $smarty-&gt;fetch("string:$htmlBody");
    }
    $mailParams['html'] = $htmlBody;
  }
  </code></pre>
  
  <p>with:</p>
  
  <pre><code>$pmf = isset($contact['preferred_mail_format']) ?   $contact['preferred_mail_format'] : 'Both';
  if ($pmf != "Both" &amp;&amp; $pmf != "Text" &amp;&amp; $pmf != "HTML") {
      $pmf = "Both";
  }
  if ($text &amp;&amp; ($test || $pmf == 'Text' || $pmf == 'Both' ||
          ($pmf == 'HTML' &amp;&amp; !array_key_exists('html', $pEmails))
  )
  ) {
      $textBody = implode('', $text);
      if ($useSmarty) {
          $textBody = $smarty-&gt;fetch("string:$textBody");
      }
      $mailParams['text'] = $textBody;
  }
  
  if ($html &amp;&amp; ($test || ($pmf == 'HTML' || $pmf == 'Both' ))) {
      $htmlBody = implode('', $html);
      if ($useSmarty) {
          $htmlBody = $smarty-&gt;fetch("string:$htmlBody");
      }
      $mailParams['html'] = $htmlBody;
  }
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-09-26T09:24:35.380Z
Answers.LastActivityDate: 2016-09-26T09:24:35.380Z
Answers.UserDisplayName: nielo
Body: <p>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:</p>
  
  <blockquote>
    <p>CiviMail will not send an empty email body, Skipping: xxxxx</p>
  </blockquote>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p>I have corrected by hand and all mails are gone.</p>
  
  <p>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.</p>
  
  <p>Regards.</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-11-23T19:45:28.737Z
Comments.Text: Take a look at [Unknown mailing status on few mailings recipients](http://civicrm.stackexchange.com/a/15965/104).
Comments.UserDisplayName: Francesc Bassas i Bullich
Tags: <civimail>
Title: Mail not send if preferred_mail_format is NULL
ThreadText: # Mail not send if preferred_mail_format is NULL
  
  (Asked by: username_0 on 2016-09-17)
  
  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.
  
  **Tags:** civimail
  
  > **Comments:**
  > **username_1**: Take a look at [Unknown mailing status on few mailings recipients](http://civicrm.stackexchange.com/a/15965/104).  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2016-09-26. Score: 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;
  }
  
  ```
  
  
  ---
  
  