如何隐藏收件人列表?在电子邮件中,每个人都可以看到还有谁收到了电子邮件,我希望他们只能将自己视为收件人
$email = array();
array_push($email, $user_info - > user_email);
$uni = array();
$uni = array_unique($email);
/* var_dump($uni);
exit;*/
wp_mail($uni, $subject, $message);
// wp_mail( 'admin mail', $subject, $message );
完整的代码是这样,我会为所有新帖子发送一封电子邮件给属于会员计划一部分的所有用户,该会员计划限制了帖子的1个或多个类别。 如果在帖子中选择了某个用户所属的特定类别,则该用户将收到一封电子邮件通知:
//Function to change email address
/*function wpb_sender_email( $original_email_address ) {
return 'mail from';
}
//Function to change sender name
function wpb_sender_name( $original_email_from ) {
return 'mail from name';
}
// Hooking up our functions to WordPress filters
add_filter( 'wp_mail_from', 'wpb_sender_email' );
add_filter( 'wp_mail_from_name', 'wpb_sender_name' );*/
function post_unpublished( $new_status, $old_status, $post ) {
//initialize the function when a post is published
if ( $old_status != 'publish' && $new_status == 'publish' ) {
//grab post ID
$post_id = $post->ID;
//get all users
$users = get_users( array( 'fields' => array( 'ID' ) ) );
$email = array();
//grab post URL
$post_url = get_permalink( $post_id );
//set email subject
$subject = 'Tst Posts';
//set email content
$message = "A new post came out:\n\n";
$message .= $post->post_title . ": " . $post_url;
//grab post rules
$rules = wc_memberships()->get_rules_instance()->get_post_content_restriction_rules( $post_id );
foreach($users as $user_id){
//grab the ID of every user
$user_info = get_userdata($user_id->ID);
$args = array( 'status' => array( 'active' ));
//get active memberships of the user
$plans = wc_memberships_get_user_active_memberships( $user_info, $args );
$user_plans = array();
//grab ID of the membership plans
foreach($plans as $plan){
array_push($user_plans,$plan->plan_id);
}
foreach($rules as $rule){
if(in_array($rule->get_membership_plan_id(), $user_plans)){
//grab email of users
if ( ! empty( $plans ) ) {
array_push($email,$user_info->user_email);
}
}
}
}
//merge identical emails since same user may be on multiple categories
$uni=array();
$uni=array_unique($email);
$headers .= 'Bcc: '. implode(",", $uni) . "\r\n";
wp_mail( null, $subject, $message, $headers );
// wp_mail( 'admin mail', $subject, $message );
}
}
add_action( 'transition_post_status', 'post_unpublished', 10, 3 );