1

I'm trying to write a HTML e-mail and fire it off with PHP (wp_mail to be exact).

It works fine in the gmail client, but if I open it up in Apple Mail, my foreach content ends up at the bottom of the e-mail, which is no good.

I'm creating the message part of the e-mail using $message .= ''; to add new bits of content. When I get to the foreach I'm doing this:

$message .= '<tr style="padding: 20px 10px; width: 100%; display: inline-block;">
        <td valign="top" style="width:100%; display:block;"><table width="100%" border="0" cellspacing="0" cellpadding="0" style="color: #767572; padding: 10px;">
          <tr>
            <td style="font-family: Helvetica, Arial, sans-serif; line-height: 130%; color: #767572;">';




foreach( $event_query->posts as $post ) : ?>


    <?php 

        $eventlink = get_permalink();
        $title = get_the_title();

        $message .= '<div class="event clearfix">';
        $message .= '<div class="event-image grid-1-4 no-padding">';

        $message .= '<h2><a href="'.$eventlink.'">'.$title.'</a></h2>';

    ?>

After the endforeach there is more content signing the e-mail off. But on Apple Mail the foreach shows after the end of the e-mail.

Any ideas?

lukeseager
  • 2,365
  • 11
  • 37
  • 57

1 Answers1

1

You're not closing your html tags properly for starters and you should avoid using divs.

$message .= '<tr style="padding: 20px 10px; width: 100%; display: inline-block;">
        <td valign="top" style="width:100%; display:block;"><table width="100%" border="0" cellspacing="0" cellpadding="0" style="color: #767572; padding: 10px;">
          <tr>
            <td style="font-family: Helvetica, Arial, sans-serif; line-height: 130%; color: #767572;">';

foreach( $event_query->posts as $post ) : ?>

  <?php 

    $eventlink = get_permalink();
    $title = get_the_title();

    $message .= '<div class="event clearfix">';
    $message .= '<div class="event-image grid-1-4 no-padding">';

    $message .= '<h2><a href="'.$eventlink.'">'.$title.'</a></h2>';

    $message .= '</div></div>';

?>

Live and breathe this guide - http://www.campaignmonitor.com/resources/will-it-work/guidelines/

Scott Joudry
  • 883
  • 10
  • 25