(对不起,我的英语)我是从wordpress开始的,这是一个简单的代码,可以在wpcf7_before_send_mail的密件抄送字段中写电子邮件?谢谢 (请注意,我必须使用wpcf7_before_send_mail而不是联系表格7中的“邮件”标签)
答案 0 :(得分:0)
您可以尝试
add_action('wpcf7_before_send_mail','dynamic_addcc');
function dynamic_addcc($WPCF7_ContactForm){
// Check contact form id.
if (33 == $WPCF7_ContactForm->id()) {
$currentformInstance = WPCF7_ContactForm::get_current();
$contactformsubmition = WPCF7_Submission::get_instance();
if ($contactformsubmition) {
$cc_email = array();
/* -------------- */
// replace with your email field's names
if(is_email($_POST['friend1-email'])){
array_push($cc_email, $_POST['friend1-email']);
}
if(is_email($_POST['friend2-email'])){
array_push($cc_email, $_POST['friend2-email']);
}
/* -------------- */
// saparate all emails by comma.
$cclist = implode(', ',$cc_email);
$data = $contactformsubmition->get_posted_data();
if (empty($data))
return;
$mail = $currentformInstance->prop('mail');
if(!empty($cclist)){
$mail['additional_headers'] = "Cc: $cclist";
}
// Save the email body
$currentformInstance->set_properties(array(
"mail" => $mail
));
// return current cf7 instance
return $currentformInstance;
}
}
}
此挂钩(wpcf7_before_send_mail)将在发送电子邮件之前运行,因此您也可以修改当前表单数据。