This happens in function _simplenews_template_mail_alter_simplenews_node. This function probably shouldn't even be executed for confirmation emails. Here is the code in question:

  $content = $message['body']['body'];

  // Retrive and filter the header content
  $header = _simplenews_template_get_header($tid);
  $header = check_markup($header, _simplenews_template_get_header_format($tid), false);

  // Retrive and filter the footer content
  $footer = _simplenews_template_get_footer($tid);
  $footer = check_markup($footer, _simplenews_template_get_footer_format($tid), false);

  // Add headers and footer
  $content = theme('simplenews_template_content', $newsletter->name, $node->title, $header, $content, $footer);

  // Fetch Simplenews Template styling for this newsletter
  $style = _simplenews_template_get_css($tid);
  $bgcolor = _simplenews_template_get_bgcolor($tid);

  // Markup node body with Simplenews Template style
  $content = theme('simplenews_template_mail', $newsletter->name, $node->title, $content, $style, $bgcolor);

  // Run HTML and CSS through Emogrifier, if available
  $content = _simplenews_template_emogrify($content, $css);

  $message['body']['body'] = $content;

For a confirmation email, $message['body']['body'] doesn't exist. I'm not sure why this results in '<' getting added to the beginning of $message['body'], but that's what's happening.

This fixed the problem for me (but I'm sure there's a better solution):

  $content = $message['body']['body'];

  if (strlen(trim($content)) > 0) {
    // Retrive and filter the header content
    $header = _simplenews_template_get_header($tid);
    $header = check_markup($header, _simplenews_template_get_header_format($tid), false);
  
    // Retrive and filter the footer content
    $footer = _simplenews_template_get_footer($tid);
    $footer = check_markup($footer, _simplenews_template_get_footer_format($tid), false);
  
    // Add headers and footer
    $content = theme('simplenews_template_content', $newsletter->name, $node->title, $header, $content, $footer);
  
    // Fetch Simplenews Template styling for this newsletter
    $style = _simplenews_template_get_css($tid);
    $bgcolor = _simplenews_template_get_bgcolor($tid);
  
    // Markup node body with Simplenews Template style
    $content = theme('simplenews_template_mail', $newsletter->name, $node->title, $content, $style, $bgcolor);
  
    // Run HTML and CSS through Emogrifier, if available
    $content = _simplenews_template_emogrify($content, $css);
  
    $message['body']['body'] = $content;
  }

Comments

adamo’s picture

My bad, the above looked like it worked at first, but it doesn't... Referencing $message['body']['body'] when only $message['body'] exists apparently grabs the first character from $message['body']. So $content gets filled with the first character of the message body and then the header/footer/etc are added to that, then $message['body']['body'] = $content; ends up replacing the first character of the message body with the first character of $content which is '<'. This really does fix it:

  if (is_array($message['body']['body'])) {
    $content = $message['body']['body'];

    // Retrive and filter the header content
    $header = _simplenews_template_get_header($tid);
    $header = check_markup($header, _simplenews_template_get_header_format($tid), false);
  
    // Retrive and filter the footer content
    $footer = _simplenews_template_get_footer($tid);
    $footer = check_markup($footer, _simplenews_template_get_footer_format($tid), false);
  
    // Add headers and footer
    $content = theme('simplenews_template_content', $newsletter->name, $node->title, $header, $content, $footer);
  
    // Fetch Simplenews Template styling for this newsletter
    $style = _simplenews_template_get_css($tid);
    $bgcolor = _simplenews_template_get_bgcolor($tid);
  
    // Markup node body with Simplenews Template style
    $content = theme('simplenews_template_mail', $newsletter->name, $node->title, $content, $style, $bgcolor);
  
    // Run HTML and CSS through Emogrifier, if available
    $content = _simplenews_template_emogrify($content, $css);
  
    $message['body']['body'] = $content;
  }
adamo’s picture

Sheesh. Ignore all the other code I posted. The real issue this:

  • The function simplenews_template_mail_alter() will call function _simplenews_template_mail_alter_{$message['id']} if it exists.
  • If it doesn't exist, it calls _simplenews_template_mail_alter_simplenews_node by default.
  • For subscription confirmation emails, $message['id'] will be 'simplenews_subscribe' and likewise for un-subscription confirmation emails $message['id'] will be 'simplenews_unsubscribe'.
  • There are no _simplenews_template_mail_alter_simplenews_subscribe or _simplenews_template_mail_alter_unsubscribe functions, so _simplenews_template_mail_alter_simplenews_node is called by default.

Adding some empty placeholder functions in the "simplenews templating callbacks" section solves the problem:

/**
 * Placeholder function for subscribe emails
 */
function _simplenews_template_mail_alter_simplenews_subscribe(&$message) {
  // Do nothing
}

/**
 * Placeholder function for unsubscribe emails
 */
function _simplenews_template_mail_alter_simplenews_unsubscribe(&$message) {
  // Do nothing
}
franz’s picture

Status: Active » Fixed

This does not seem to be a problem anymore (check last dev version)

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.