Title: Fixed Plugin
Last modified: August 31, 2016

---

# Fixed Plugin

 *  [receter](https://wordpress.org/support/users/receter/)
 * (@receter)
 * [10 years, 1 month ago](https://wordpress.org/support/topic/fixed-plugin-1/)
 * HI Tobias,
 * I fixed the plugin to work with the newest version of WP and CF7. Just get in
   contact with me and I can send you the fixed code.
 * Thanks for your work, it was really useful for me.
 * [https://wordpress.org/plugins/contact-form-7-mail-conditions/](https://wordpress.org/plugins/contact-form-7-mail-conditions/)

Viewing 9 replies - 1 through 9 (of 9 total)

 *  [c353464](https://wordpress.org/support/users/c353464/)
 * (@c353464)
 * [10 years, 1 month ago](https://wordpress.org/support/topic/fixed-plugin-1/#post-7265011)
 * Hey receter,
 * Can you upload/pastebin your code somewhere in the meantime?
 * Thanks in advance!
 *  Thread Starter [receter](https://wordpress.org/support/users/receter/)
 * (@receter)
 * [10 years ago](https://wordpress.org/support/topic/fixed-plugin-1/#post-7265067)
 * This should do the trick:
 *     ```
       /**
       	 * Modifies the emails by replacing the conditionals [if field_name][/if]
       	 *
       	 * @param [Object] $cf7 the contanct form 7 object
       	 * @return void
       	 * @author Tobias Braner
       	 **/
       	public function before_send_mail($contact_form) {
         		$submission = WPCF7_Submission::get_instance();
       		if ( $submission ) {
       			$posted_data = $submission->get_posted_data();
       			$mail = $contact_form->prop('mail');
       			$mail2 = $contact_form->prop('mail2');
       			$mail_body = $mail['body'];
       			$mail2_body = $mail2['body'];
       			$mail['body'] = $this->process_conditions($mail_body, $posted_data);
       			$mail2['body'] = $this->process_conditions($mail2_body, $posted_data);
       			$contact_form->set_properties(array('mail' => $mail, 'mail2' => $mail2));
       		}
       	}
   
       	/**
       	 * Takes the wpcf7 object and replaces all conditions.
       	 *
       	 * @return void
       	 * @author Tobias Braner
       	 **/
       	private function process_conditions($mail_body, $posted_data) {
       		$updated_email_body = $mail_body;
       		$matches = array();
       		$num_matches = preg_match_all($this->regexp, $mail_body, $matches);
       		for ($i=0; $i < $num_matches; $i++) {
       			$expression = $matches[WPCF7MC_EXPRESSION][$i];
       			$variable = $matches[WPCF7MC_VARIABLE][$i];
       			$value = $matches[WPCF7MC_VALUE][$i];
       			if (empty($posted_data[$variable][0]) and array_key_exists($variable, $posted_data)) {
       				$updated_email_body = str_replace($expression, '', $updated_email_body);
       			} else {
       				$updated_email_body = str_replace($expression, $value, $updated_email_body);
       			}
       		}
       		return $updated_email_body;
       	}
       ```
   
 *  [sassan](https://wordpress.org/support/users/sassan/)
 * (@sassan)
 * [10 years ago](https://wordpress.org/support/topic/fixed-plugin-1/#post-7265068)
 * Dear receter,
 * thank you very much for your quick reply. But, I’m not experienced enough to 
   know what to do with that code. Is there a simple way for me to get this running?
   Could you provide a simple step-by-step instruction? How can I pay you for your
   efforts? Please feel free to contact me directly or post the information here
   for everybody to benefit from it.
 * Thank you very much in advance.
 *  Thread Starter [receter](https://wordpress.org/support/users/receter/)
 * (@receter)
 * [10 years ago](https://wordpress.org/support/topic/fixed-plugin-1/#post-7265070)
 * There is just one very short file in the plugin folder (besides the readme.txt).
   Open it and replace the functions inside with the functions I sent you. If you
   need further assistance, my email address is my wordpress username at gmail com.
 *  [kim.oj](https://wordpress.org/support/users/kimoj/)
 * (@kimoj)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/fixed-plugin-1/#post-8790055)
 * Made a smal adjustment to [@receter](https://wordpress.org/support/users/receter/)’
   s code to make the plugin work with mail(2) in CF7 Version 4.4
 * mail2 > mail_2
 *     ```
       	 /**
       	 * Modifies the emails by replacing the conditionals [if field_name][/if]
       	 *
       	 * @param [Object] $cf7 the contanct form 7 object
       	 * @return void
       	 * @author Tobias Braner
       	 **/
       	public function before_send_mail($contact_form) {
         		$submission = WPCF7_Submission::get_instance();
       		if ( $submission ) {
       			$posted_data = $submission->get_posted_data();
       			$mail = $contact_form->prop('mail');
       			$mail_2 = $contact_form->prop('mail_2');
       			$mail_body = $mail['body'];
       			$mail_2_body = $mail_2['body'];
       			$mail['body'] = $this->process_conditions($mail_body, $posted_data);
       			$mail_2['body'] = $this->process_conditions($mail_2_body, $posted_data);
       			$contact_form->set_properties(array('mail' => $mail, 'mail_2' => $mail_2));
       		}
       	}
       ```
   
    -  This reply was modified 9 years, 3 months ago by [kim.oj](https://wordpress.org/support/users/kimoj/).
 *  [safak93](https://wordpress.org/support/users/safak93/)
 * (@safak93)
 * [9 years, 1 month ago](https://wordpress.org/support/topic/fixed-plugin-1/#post-8985696)
 * Hello guys,
 * How can I check the checkbox if there is selected a specific option?
 * Like:
    if[checkbox_id/name=”blue”]Selected color: blue[/if] if[checkbox_id/name
   =”green”]Selected color: green[/if]
 *  [kim.oj](https://wordpress.org/support/users/kimoj/)
 * (@kimoj)
 * [9 years, 1 month ago](https://wordpress.org/support/topic/fixed-plugin-1/#post-8989999)
 * Hi,
    if you have this in your form
 * `[checkbox checkbox-961 "test 1" "test 2" "test 3"]`
 * Then you just need to write this in your mail
 * `[checkbox-961]`
 * If you want to print something in the form, I unfortunately don’t have a answer.
 *  [safak93](https://wordpress.org/support/users/safak93/)
 * (@safak93)
 * [9 years, 1 month ago](https://wordpress.org/support/topic/fixed-plugin-1/#post-8990137)
 * Hello,
 * I explained it wrong. Sorry about that.
 * So basically I want that the e-mail should have a condition for additional informations(
   internal purpose) based of the selected checkboxes:
 * if[checkbox_id/name=”test1”]Information: xyz[/if]
    if[checkbox_id/name=”test2”]
   Information: abc[/if] if[checkbox_id/name=”test3”]Information: cdf[/if]
 *  [kim.oj](https://wordpress.org/support/users/kimoj/)
 * (@kimoj)
 * [9 years, 1 month ago](https://wordpress.org/support/topic/fixed-plugin-1/#post-9023121)
 * I couldn’t figure that one out with one input, so I made separately input fields
   for every question I wanted to check.
 * Hope you find another answer!
    /Kim

Viewing 9 replies - 1 through 9 (of 9 total)

The topic ‘Fixed Plugin’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/contact-form-7-mail-conditions.svg)
 * [Contact Form 7 Mail Conditions](https://wordpress.org/plugins/contact-form-7-mail-conditions/)
 * [Support Threads](https://wordpress.org/support/plugin/contact-form-7-mail-conditions/)
 * [Active Topics](https://wordpress.org/support/plugin/contact-form-7-mail-conditions/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/contact-form-7-mail-conditions/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/contact-form-7-mail-conditions/reviews/)

 * 9 replies
 * 5 participants
 * Last reply from: [kim.oj](https://wordpress.org/support/users/kimoj/)
 * Last activity: [9 years, 1 month ago](https://wordpress.org/support/topic/fixed-plugin-1/#post-9023121)
 * Status: not resolved