ccurtin
9/21/2015 - 7:52 PM

Display custom email messages depending on the values selected in a contact form.

Display custom email messages depending on the values selected in a contact form.

<?php

add_action('wpcf7_before_send_mail','wpcf7_update_email_body');

function wpcf7_update_email_body($contact_form) {

	$page_id = $contact_form->id();

	if($page_id == 1375):

 		$submission = WPCF7_Submission::get_instance();

  		if( $submission ) {
		 	$form = $submission->get_posted_data();
		  $mail = $contact_form->prop('mail');
			$date = implode($form['select-dates'], "");
			$customMessage = '';
			$doItAgain =  $mail['body'];

			// JUST october 24
			if($date == "October 24"){
			  $mail['subject'] = "ASA 2015 Confirmation - October 24th";
			  $form['mail-info'] = "
			  Thank you for registering for Anesthesiology 2015!<br>
			 
			  Your confirmation is below:<br>
			  Saturday, October 24, 1:30 p.m. - The Exhibit Hall, Hall C by aisle 2300, Theater #1
			  ";
			} else 
			// JUST october 25
			if($date == "October 25"){
			  $mail['subject'] = "ASA 2015 Confirmation - October 25th";
			  $form['mail-info'] = "
			  Thank you for registering for Anesthesiology 2015!<br>

			  Your confirmation is below:<br>
			  Sunday, October 25, 1:30 p.m. - The Exhibit Hall, Hall C by aisle 2300, Theater #1
			  ";
			} else {
			// BOTH DAYS
			  $mail['subject'] = "ASA 2015 Confirmation - October 24-25";
			  $form['mail-info'] = "
			  Thank you for registering for Anesthesiology 2015!<br>
			 
			  Your confirmation is below:<br>
			  Saturday, October 24, 1:30 p.m. - The Exhibit Hall, Hall C by aisle 2300, Theater #1
			  Sunday, October 25, 1:30 p.m. - The Exhibit Hall, Hall C by aisle 2300, Theater #1
			  ";
			}
			$mail['body'] = $form['mail-info'] . "<br><br>" . $doItAgain;
    	$contact_form->set_properties(array('mail' => $mail));
  		}
	endif;
}
?>