简体   繁体   中英

foreach in HTML E-Mail breaks in Apple Mail

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?

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/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM