[英]PHP Mail Format with ACF Repeater field
I'm developing a module to send mails from a WordPress post, using some custom fields from ACF.我正在开发一个模块来从 WordPress 帖子发送邮件,使用 ACF 的一些自定义字段。
I have an initial structure like:我有一个初始结构,如:
$to = $wpp_send_status_email;
$subject = $wpp_send_status_subject;
$body = "
<html>
<table border='0' cellpadding='0' cellspacing='0' style='background: #fff; max-width:670px;margin:40px auto;text-align:left;color:#000;border: 1.3px solid rgba(0, 0, 0, 0.05);-webkit-border-radius: 10px;-moz-border-radius: 10px;border-radius: 10px;-webkit-box-shadow: 0px 5px 15px -10px rgba(0, 0, 0, 0.2); box-shadow: 0px 5px 15px -10px rgba(0, 0, 0, 0.2)'>
The code works okay, but when I have to use the repeater field with if and else options, I don't have success.代码工作正常,但是当我必须使用带有 if 和 else 选项的转发器字段时,我没有成功。 My original code is:我的原始代码是:
<?php if(get_field('to-do')): ?>
<tbody>
<tr>
<th style="font-family:Arial,sans-serif;text-align: left; vertical-align: middle; padding: 0 0 20px 0; font-size: 14px">Tarefa</th>
<th style="font-family:Arial,sans-serif;text-align: left; vertical-align: middle; padding: 0 0 20px 0; font-size: 14px">Deadline</th>
<th style="font-family:Arial,sans-serif;text-align: left; vertical-align: middle; padding: 0 0 20px 0; font-size: 14px">Status</th>
</tr>
<?php while(has_sub_field('to-do')): ?>
<tr style="border-top: 1px solid rgba(0, 0, 0, 0.05)">
<td class="timeline-phase-activity ng-scope" style="text-align: left;vertical-align:middle;font-size:14px;width:60%;font-family:Arial,sans-serif;padding:10px 30px 10px 0"><span><?php the_sub_field('task-name'); ?></span></td>
<td style="vertical-align:middle;text-align:left;padding-left: 24px;font-size:14px;font-family:Arial,sans-serif;padding:10px 0">
<span style="padding-right:1.125rem"><?php the_sub_field('deadline'); ?></span>
</td>
<td style="text-align:left;vertical-align:middle;font-size:14px;font-family:Arial,sans-serif;;padding:10px 0"><span><?php the_sub_field('status'); ?></span>
</td>
</tr>
<?php endwhile; ?>
</tbody>
<?php endif; ?>
Does anyone know how I include this inside HTML tag?有谁知道我如何将它包含在 HTML 标签中? My other field is on the " . get_field('conclusion', $post->ID) . " structure, but this doesn't work with if and else.我的另一个字段位于“ . get_field('conclusion', $post->ID) . ”结构上,但这不适用于 if 和 else。
If I got your question correctly, you're looking for a way to get this content into the $body
variable.如果我正确地回答了您的问题,那么您正在寻找一种方法将这些内容放入$body
变量中。 This can be best achieved using output buffering like so:这可以通过使用输出缓冲来最好地实现,如下所示:
$to = $wpp_send_status_email;
$subject = $wpp_send_status_subject;
ob_start(); // start the output buffering
if(get_field('to-do')): ?>
<tbody>
<tr>
<th style="font-family:Arial,sans-serif;text-align: left; vertical-align: middle; padding: 0 0 20px 0; font-size: 14px">Tarefa</th>
<th style="font-family:Arial,sans-serif;text-align: left; vertical-align: middle; padding: 0 0 20px 0; font-size: 14px">Deadline</th>
<th style="font-family:Arial,sans-serif;text-align: left; vertical-align: middle; padding: 0 0 20px 0; font-size: 14px">Status</th>
</tr>
<?php while(has_sub_field('to-do')): ?>
<tr style="border-top: 1px solid rgba(0, 0, 0, 0.05)">
<td class="timeline-phase-activity ng-scope" style="text-align: left;vertical-align:middle;font-size:14px;width:60%;font-family:Arial,sans-serif;padding:10px 30px 10px 0"><span><?php the_sub_field('task-name'); ?></span></td>
<td style="vertical-align:middle;text-align:left;padding-left: 24px;font-size:14px;font-family:Arial,sans-serif;padding:10px 0">
<span style="padding-right:1.125rem"><?php the_sub_field('deadline'); ?></span>
</td>
<td style="text-align:left;vertical-align:middle;font-size:14px;font-family:Arial,sans-serif;;padding:10px 0"><span><?php the_sub_field('status'); ?></span>
</td>
</tr>
<?php endwhile; ?>
</tbody>
<?php
endif;
$body = ob_get_clean(); // retrieve the output buffer and save to $body
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.