无需编写任何代码,联系人表单7在Mail
部分您只需在中的“附加邮件头”文本框中写入电子邮件的邮件头Mail
(第二个选项卡)部分。
将其放入“附加标题”文本框中。
Cc: [friend1-email], [friend2-email], [friend3-email], [friend4-email], [friend5-email]
或
您可以通过挂钩更改电子邮件标题数据wpcf7_before_send_mail
尝试以下代码。
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
钩子在发送电子邮件之前运行,您可以修改表单数据。