发送自定义字段值到电子邮件
问题描述:
我创建了自定义帖子类型命名电子邮件,并添加了一个自定义字段使用高级自定义字段插件到自定义帖子类型中的一个帖子称为电子邮件页脚,该字段是图像字段,应该显示在每个自动电子邮件的底部都会出现在网站之外。发送自定义字段值到电子邮件
我使用
function wpcf7ev_verify_email_address2($wpcf7_form){
$email_footer = '<html>
<body style="color:#000000;">
<div style="font-size:16px;font-weight:bold;margin-top:20px;">
Regards,
<br/>
$email_footer .= '<img src="http://mysite.col/footer_image.jpg" width="100%" alt=""/>
</div>';
$email_footer .='<div style="display:none;">'.generateRandomString().
'</div></body>
</html>
';
的代码工作当前的代码,它显示的图像与此网址在底部:http://mysite.col/footer_image.jpg
,但我不想硬编码的,我想能够与我创建
我看着ACF的文档,发现这个自定义字段来修改它,但我不知道如何使用它仍然显示,自定义后类型确切的领域,我创建:
<?php
$image = get_field('image');
if(!empty($image)): ?>
<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" />
<?php endif; ?>
答
你从ACF文件中列出的代码将告诉您如何使用图片(与类型的数组),以获得从ACF领域的形象。
如果我们要在你的函数中实现这个功能,我们必须在某个地方从页面引用图像。不知道你是怎么称呼它的,有几种方法可以嵌入它。
第一种方式,我们通过它完成的调用页面上的功能,像这样......
wpcf7ev_verify_email_address2(get_field('image'));
,然后更新您的函数是这样的...
function wpcf7ev_verify_email_address2($image, $wpcf7_form)
{
$email_footer = '<div style="font-size:16px;font-weight:bold;margin-top:20px;">Regards,<br/>';
// get the image from the passed in image function.
$email_footer .= '<img src="' . $image['url'] . '" width="100%" alt="' . $image['alt'] . '"/></div>';
$email_footer .='<div style="display:none;">' . generateRandomString() . '</div>';
}
或者,第二种方法,如果您要调用该功能来修改某个动作或其他内容,则必须从您的ACVF设置中分配的任何页面ID /选项页面获取该图像。这将使你的函数看起来有点像这样:
function wpcf7ev_verify_email_address2($wpcf7_form)
{
// get image acf field from page with id 1
$image = get_field('image', 1);
// or get image from acf field on options page
// $image = get_field('image', 'options');
$email_footer = '<div style="font-size:16px;font-weight:bold;margin-top:20px;">Regards,<br/>';
$email_footer .= '<img src="' . $image['url'] . '" width="100%" alt="' . $image['alt'] . '"/></div>';
$email_footer .='<div style="display:none;">' . generateRandomString() . '</div>';
}
的所有上述的假设,你的功能是否按预期运行,你需要帮助抓住ACF领域,图像上传。如果需要,您可以在if
声明中包装get_field的声明。