如何解决无法使用 acf_form_head() 和 wp_mail 从 ACF 用户电子邮件数组发送电子邮件
这里我有一个函数“email_group_members”,它向 wp-admin 中的 CPT 添加一个元框。 然后我有另一个函数“group_members_html()”,它添加了高级自定义字段“acf_form_head()”函数,该函数通过发送按钮添加了“标题”和“内容”输入。
我花了很长时间试图弄清楚为什么没有发送电子邮件。电子邮件数据的 foreach 当前确实返回。
基本上,我正在尝试在管理员 CPT 中创建一个表单,该表单向“$user_email”中的用户电子邮件发送电子邮件。
任何指导都会非常有帮助和赞赏。
function email_group_members() {
$screens = [ 'groupmembers','' ];
foreach ( $screens as $screen ) {
add_meta_box(
'email_group_id',// Unique ID
'Email Group Members',// Box title
'group_members_html',// Content callback,must be of type callable
$screen // Post type
);
}
}
add_action( 'add_meta_boxes','email_group_members' );
function group_members_html() {
global $post;
$users = get_field("select_users_for_group");
if( $users ) {
acf_form_head(); ?>
<div id="content">
<?php
acf_form(array(
'post_id' => 'new_post','post_title' => true,'post_content' => true,'new_post' => array(
'post_type' => 'contact_membership','post_status' => 'publish'
),'return' => home_url('contact-form-thank-you'),'submit_value' => 'Send'
));
?>
</div>
<?php
add_action('acf/save_post','my_save_post');
function my_save_post( $post_id ) {
foreach( $users as $user ): ?>
<?php
// vars
$post = get_post( $post_id );
$user_info = get_userdata($user);
$first_name = $user_info->first_name;
$last_name = $user_info->last_name;
$user_email = "$first_name $last_name <$user_info->user_email>";
echo "<br> $first_name | $last_name | $username | $user_email <br>";
$subject = $post->post_title;
$message = $post->post_content;
$headers = array('Content-Type: text/html; charset=UTF-8');
wp_mail( $user_email,$subject,$message,$headers);
endforeach;
}
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。