thewaysian
Forum Replies Created
Viewing 1 replies (of 1 total)
-
Forum: Plugins
In reply to: [Contact Form 7] Dynamic Email Recipient Not WorkingWebsite in question is Here
But I figured out a solution that works. I had to pull the data, implode it, and then compare it against an array using in_array. I don’t know if this was the best way to go about it, but it does work now.
//Place in wp-content/themes/neve/functions.php // hook into wpcf7_before_send_mail add_action( 'wpcf7_before_send_mail', 'cf7dynamicnotifications'); // Hooking into wpcf7_before_send_mail function cf7dynamicnotifications($contact_form) // Create our function to be used in the above hook { $submission = WPCF7_Submission::get_instance(); // Create instance of WPCF7_Submission class $posted_data = $submission->get_posted_data(); // Get all of the submitted form data $contact_form = WPCF7_ContactForm::get_current(); $form_id = $contact_form -> id; $property_city = $submission->get_posted_data('property-City'); $property_city = implode( ', ', (array) $property_city); $denverCity = array('denver', 'arvada', 'wheat ridge', 'aurora', 'parker', 'cherry creek', 'greenwood village', 'centennial', 'thornton', 'northglenn', 'commerce city'); // ILC Denver Area $south = array('lakewood', 'golden', 'castle rock', 'colorado springs', 'pueblo'); //Property Survey South Area $north = array('longmont', 'lyons', 'estes park', 'berthoud', 'loveland', 'fort collins', 'greeley', 'evans'); //Property Survey North Area if($form_id == '242'){ //ILC Code if (in_array(strtolower($property_city), $denverCity) ) { //Check for Denver Metro Cities $recipient_email = 'j@flatironsinc.com'; } else { //Otherwise send to Sterl $recipient_email = 's@flatironsinc.com'; } // set the email address to recipient $mailProp = $contact_form->get_properties('mail'); $mailProp['mail']['recipient'] = $recipient_email; // update the form properties $contact_form->set_properties(array('mail' => $mailProp['mail'])); } elseif($form_id == '233'){ //Property Survey Code if (in_array(strtolower($property_city), $south) ) { //Check for South Region $recipient_email = 'j@flatironsinc.com'; } elseif (in_array(strtolower($property_city), $north) ) { //Check for North Region $recipient_email = 'j2@flatironsinc.com'; } else { //Otherwise send to Zack $recipient_email = 'z@flatironsinc.com'; } // set the email address to recipient $mailProp = $contact_form->get_properties('mail'); $mailProp['mail']['recipient'] = $recipient_email; // update the form properties $contact_form->set_properties(array('mail' => $mailProp['mail'])); } }
Viewing 1 replies (of 1 total)