• I would like to have a contact form with a few checkboxes that will send different emails depending on which checkboxes are ticked.

    I think I could use wpcf7_before_send_mail to modify the checkbox value to either leave it blank (no email would be sent to the second person) or update the value to the appropriate email address.

    add_action('wpcf7_before_send_mail', 'wpcf7_send_second_email');
    
    function wpcf7_send_second_email($contact_form) {
         $data = $contact_form->posted_data;
         if ($data['checkbox'] == "second email") {
            $data['checkbox'] = email@email.com;
         } else {
            $data['checkbox'] = "";
         }
    }

    The part I can’t figure out is how to send more than two emails. I tried to hook into wpcf7_add_meta_boxes, but that didn’t work.

    add_action('wpcf7_add_meta_boxes', 'add_more_mail_boxes');
    
    function add_more_mail_boxes($post_id) {
    
    	add_meta_box( 'mail3div', __( 'Mail (3)', 'contact-form-7' ),
    		'wpcf7_mail_meta_box', null, 'mail_3', 'core',
    		array(
    			'id' => 'wpcf7-mail-3',
    			'name' => 'mail_3',
    			'use' => __( 'Use mail (3)', 'contact-form-7' ) ) );
    }

    So this is definitely different from a CC or BCC.

    https://wordpress.org/plugins/contact-form-7/

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Takayuki Miyoshi

    (@takayukister)

    Thread Starter danielchopkins

    (@danielchopkins)

    I don’t think that’s what I’m looking for.

    I need to send one form, but have three different emails sent. For instance:

    email one to recipient one:

    Different first line for email one.

    [all-fields]

    email two to recipient two:

    Different first line for email two.

    [all-fields]

    Etc.

    Does that make sense?

    Thread Starter danielchopkins

    (@danielchopkins)

    Is there a way to hook into wpcf7_save_contact_form?

    I figured out what I need to do in order for this to work.

    Basically, I need to duplicate all of the mail(2) functionality and make a mail(3).

    Plugin Author Takayuki Miyoshi

    (@takayukister)

    If you just want to add “Mail (3)”, you can do it with wpcf7_additional_mail filter which is used in includes/submission.php.

    Thread Starter danielchopkins

    (@danielchopkins)

    What would that look like?

    add_filter('wpcf7_additional_mail', 'my_wpcf7_additional_mail');
    
    function my_wpcf7_additional_mail {
         if ( ( $mail_3 = $contact_form->prop( 'mail_3' ) ) && $mail_3['active'] ) {
    	     $additional_mail['mail_3'] = $mail_3;
         }
    }

    But that can’t be right because this wouldn’t add a meta box to a form or save the data of that meta box.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Send multiple emails with slightly modified email bodies’ is closed to new replies.