我正在尝试制作一个表格,首先要求提供用户数据,然后发送一封包含下载我们目录的链接的电子邮件。该案例的特殊性在于,客户必须从下拉列表中选择其业务类型,并且由于目录不同,因此每个业务类型的电子邮件模板应该不同。这可以通过 CF7 表格来实现吗?
有3种方法可以实现这一目标,
mail_tag
过滤器,例如 [cf7sg-form-<your-form-name>]
,您可以将其插入邮件正文中,并且它允许您使用表单的所有提交字段以编程方式撰写邮件正文消息,以便您可以检查业务类型的值并相应地撰写邮件,(有关更多示例,请参阅此示例教程)add_filter( 'cf7sg_mailtag_cf7sg-my-custom-form', 'filter_cf7_mailtag_cf7sg_form_my_custom_form', 10, 3);
function filter_cf7_mailtag_cf7sg_form_my_custom_form($tag_replace, $submitted, $cf7_key){
/*the $tag_replace string to change*/
/*the $submitted an array containing all submitted fields*/
/*the $cf7_key is a unique string key to identify your form, which you can find in your form table in the dashboard.*/
if('my-custom-form'==$cf7_key ){
switch($submitted['business-type']){
case 'type1':
$body = ... //the message body for type1 businesses.
break;
case 'type2':
$body = ... //the message body for typee businesses.
break;
default:
$body = "Unknown business".
break;
}
return $body;
}
wpcf7_mail_components
,它允许您过滤插件用于创建和发送通知邮件的所有组件,add_filter('wpcf7_mail_components', 'filter_cf7_mail_components',10,3);
function filter_cf7_mail_components($components, $form_obj, $wpcf7_mail_object){
$components['subject'];
$components['sender'];
$components['body']; //this is the one you want to change.
$components['additional_headers'];
$components['attachments'];
return $components;
}
这个论坛上有很多关于CF7 wpcf7_mail_components
过滤器的
问题/答案。