admin管理员组文章数量:1279177
Can I put any type of custom shortcode for some content in mail body?
eg:
$to = "[email protected]";
$subject = "Test Email";
$packages = do_shortcode('[test id="0000"]');
$message = $packages;
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
// More headers
$headers .= 'From: <[email protected]>' . "\r\n";
mail($to,$subject,$message,$headers)
Can I put any type of custom shortcode for some content in mail body?
eg:
$to = "[email protected]";
$subject = "Test Email";
$packages = do_shortcode('[test id="0000"]');
$message = $packages;
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
// More headers
$headers .= 'From: <[email protected]>' . "\r\n";
mail($to,$subject,$message,$headers)
Share
Improve this question
edited Feb 7, 2019 at 19:49
fuxia♦
107k38 gold badges255 silver badges459 bronze badges
asked Jan 8, 2019 at 17:39
Pratik PatelPratik Patel
1,1111 gold badge11 silver badges23 bronze badges
1 Answer
Reset to default 1The shortcode generation should output a string, so that should in theory be possible if you know and trust the shortcode's output.
But many shortcodes are generated with the front-end in mind and within the loop context, so the mail context might not always work though, if they depend on conditional checks like is_single()
.
There is the shortcode_exists()
function to make sure the shortcode exists.
It's also possible to use the shortcode's callback directly, instead of having to run the complicated parsing of do_shortcode()
.
You might also add some validations regarding the shortcode's output, before mailing it. Like do you want allow sending an empty string?
You should also hook your mailing code, after the shortcode has been added within the init
action.
Note that WordPress uses the wp_mail()
wrapper that plugins can hook into.
本文标签: Can I use shortcodes in mail body
版权声明:本文标题:Can I use shortcodes in mail body 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741276225a2369742.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论