有两种方法可以实现这一点
1使用“wpcf7\\u mail\\u components”挂钩,修改电子邮件收件人或抄送列表,
add_filter( \'wpcf7_mail_components\', \'change_email_address\',10,3);
function change_email_address($components, $form, $mailobj){
//get the $users....
foreach($users as $key => $user){
$email = $user->user_email;
//either as in the recipient list,
$components[\'recipient\'].=\',\'.$email;
//or add in cc
$cc=$email.\',\';
}
$components[\'additional_headers\']=\'cc:\'.$cc;
return $components;
}
2使用“wpcf7\\u additional\\u mail”创建其他电子邮件,
add_filter( \'wpcf7_additional_mail\', \'send_additional_mails\',10,2);
function send_additional_mails($mails, $form){
//$mails will container the maail_2 template if you have enabled it.
//reset it if you don\'t want to send mail_2, but just using it as an additional mail template.
$mails = array();
//get the $users....
foreach($users as $key => $user){
$email = $user->user_email;
//copy your mail template
$template = $form->prop(\'mail\');
//or if you have enabled mail 2 template, you can use that instead.
$template = $form->prop(\'mail_2\');
//add the mail to the recipient list...
$template[\'recipient\'] = $email ;
$mails[$email] = $template;
}
return $mails;
}
设置好模板后,可以挂接“wpcf7\\u mail\\u组件”,进一步过滤其他邮件。