I'm trying to make a form that asks for user data first and then sends an email with a link to download our catalog. The particularity of the case is that the customer have to select his business type from a dropdown and the email template should be different for each one since the catalogs are different. Can this be achieved with a CF7 form?
There are 3 ways to achieve this,
mail_tag
filter such as [cf7sg-form-<your-form-name>]
which you can insert into the body of your mail, and it allows you to programmatically compose your mail body message using all the submitted fields of your form, so you can check the value of the business type and compose the mail accordingly, (see this example tutorial for more examples)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
which allows you to filter all the components used by the plugin to create and send the notification mail,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;
}
There are quite a few questions/answers on the CF7 wpcf7_mail_components
filter on this forum.