Title: Conditional emails
Last modified: April 11, 2024

---

# Conditional emails

 *  Resolved [pkon](https://wordpress.org/support/users/pkonings/)
 * (@pkonings)
 * [2 years, 1 month ago](https://wordpress.org/support/topic/conditional-emails/)
 * Hello Roy,
   What a great plug-in!I was wondering if there is any way we could 
   expand on the code to create a condition in which either email(2) email(3) or
   email(4) etc. get’s send, and not the others.My goal is to create a form where
   people choose about what topic they want to receive information.I then don’t 
   want to send them an e-mail that contains attachments for all the other subjects,
   just 1 email with the information they requested.Is this something reachable?

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

 *  Plugin Author [Roy Orbitson](https://wordpress.org/support/users/lev0/)
 * (@lev0)
 * [2 years, 1 month ago](https://wordpress.org/support/topic/conditional-emails/#post-17682025)
 * Hi,
 * This plugin only creates the additional form parts for extra emails by duplicating
   what the original plugin uses in email (2). Since that does not have such conditional
   sending, nor do the extra ones. It’s not something I plan on building into this.
 * However, there is a filter called `wpcf7_additional_mail` in `[submission.php](https://plugins.trac.wordpress.org/browser/contact-form-7/trunk/includes/submission.php)`
   that can be used to inspect the current form submission and conditionally remove
   messages from that array.
 * The problem you’re describing isn’t necessarily a multiple emails issue. Wouldn’t
   it make more sense to send one email, but change its content and the set of attached
   files? That is also possible by using the filter/action hooks in CF7 and using`
   add_extra_attachments()`.
 * Regards.
 *  Thread Starter [pkon](https://wordpress.org/support/users/pkonings/)
 * (@pkonings)
 * [2 years, 1 month ago](https://wordpress.org/support/topic/conditional-emails/#post-17682128)
 * Hi Roy,
   Thank you for taking the time to respond.I think what you are suggesting
   would surely work and is even more elegant of a solution. However i’m not able
   to write a function code like that myself.With your clue’s, I might dip my toes
   into it someday and try to create somekind of code.For now the search goes on.
   🙂
 * 
   Kind Regards
 *  Plugin Author [Roy Orbitson](https://wordpress.org/support/users/lev0/)
 * (@lev0)
 * [2 years, 1 month ago](https://wordpress.org/support/topic/conditional-emails/#post-17689101)
 * Hire someone. It’s explained in [this blog post](https://contactform7.com/2020/07/28/accessing-user-input-data/),
   the form could have a checkbox set like this:
 *     ```wp-block-code
       [checkbox* interests use_label_element "a|Subject A" "b|Subject B" "c|Subject C"]
       ```
   
 * Then something like this as the body of your custom plugin:
 *     ```wp-block-code
       add_action(
           'wpcf7_before_send_mail',
           function($contact_form, &$abort, $submission) {
               $interests = (array) $submission->get_posted_data('interests');
               if (in_array('a', $interests))
                   $submission->add_extra_attachments('path/to/info-a.pdf');
               ...
           },
           10,
           3,
       );
       ```
   

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

The topic ‘Conditional emails’ is closed to new replies.

 * ![](https://ps.w.org/more-mails-for-cf7/assets/icon-256x256.jpg?rev=2094526)
 * [More Mails for CF7](https://wordpress.org/plugins/more-mails-for-cf7/)
 * [Support Threads](https://wordpress.org/support/plugin/more-mails-for-cf7/)
 * [Active Topics](https://wordpress.org/support/plugin/more-mails-for-cf7/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/more-mails-for-cf7/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/more-mails-for-cf7/reviews/)

## Tags

 * [conditional](https://wordpress.org/support/topic-tag/conditional/)

 * 3 replies
 * 2 participants
 * Last reply from: [Roy Orbitson](https://wordpress.org/support/users/lev0/)
 * Last activity: [2 years, 1 month ago](https://wordpress.org/support/topic/conditional-emails/#post-17689101)
 * Status: resolved