I have two versions of an auto responder that I would like to send out based on what the user selected from a dropdown field. So if the user selected California from the dropdown they would get autoresponder 1 and if the user selected Texas they would get auto responder 2. Is there a way to do this?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Where exactly should be this code added?
hook in to wpcf7_mail_sent - this will happen after form is submitted
add_action( 'wpcf7_mail_sent', 'contact_form_autoresponders' );
our autoresponders function
function contact_form_autoresponders( $contact_form ) {
if( $contact_form->id==1234 ){ #your contact form ID - you can find this in contact form 7 settings
#retrieve the details of the form/post
$submission = WPCF7_Submission::get_instance();
$posted_data = $submission->get_posted_data();
#set autoresponders based on dropdown choice
switch( $posted_data['location'] ){ #your dropdown menu field name
case 'California':
$msg="California email body goes here";
break;
case 'Texas':
$msg="Texas email body goes here";
break;
}
#mail it to them
mail( $posted_data['your-email'], 'Thanks for your enquiry', $msg );
}
}
回答2:
Add in functions.php -
#hook in to wpcf7_mail_sent - this will happen after form is submitted
add_action( 'wpcf7_mail_sent', 'contact_form_autoresponders' );
#our autoresponders function
function contact_form_autoresponders( $contact_form ) {
if( $contact_form->id==1234 ){ #your contact form ID - you can find this in contact form 7 settings
#retrieve the details of the form/post
$submission = WPCF7_Submission::get_instance();
$posted_data = $submission->get_posted_data();
#set autoresponders based on dropdown choice
switch( $posted_data['location'] ){ #your dropdown menu field name
case 'California':
$msg="California email body goes here";
break;
case 'Texas':
$msg="Texas email body goes here";
break;
}
#mail it to them
mail( $posted_data['your-email'], 'Thanks for your enquiry', $msg );
}
}