Title: Adding Mail (3) &#8211; coding included
Last modified: August 22, 2016

---

# Adding Mail (3) – coding included

 *  [kylee6114](https://wordpress.org/support/users/kylee6114/)
 * (@kylee6114)
 * [11 years, 4 months ago](https://wordpress.org/support/topic/adding-mail-3-coding-included/)
 * Hi all,
 * I was looking for this for a while and found nothing, so perhaps it will help
   someone (or will be included in future updates).
 * _This is for when you want to add a 3rd mail option. It will allow you to have
   Mail, Mail (2), and Mail (3) options for each of your forms._
 * **NOTE: This is NOT for just sending the same email to 3 different people (use
   commas for sending the same email to multiple recipients). This is ONLY for when
   you need to send 3 different emails.**
 * (Technically, I imagine you could continue duplicating what I’ve done and have
   a hundred mail options.)
 * It will require you editing seven (7) PHP files, so you should feel comfortable
   with that side of things. Otherwise, it’s pretty straight-forward, I think. I’ll
   supply coding lines for Notepad++, although you may see something different (
   and therefore will just have to search for them). Basically, just duplicate the
   Mail (2) and change the ‘2’ to a ‘3’. I’m including the coding before and after
   to help give some context but the only thing you’re adding are the lines for 
   Mail (3) / mail_3, etc. [This is based off of CF7 version 4.1, btw.]
 * I’ve tested it on WP 4.1 and CF7 4.1 – it works for me and is just what I needed.
   If it doesn’t work for you, sorry! However, I won’t have time to troubleshoot
   for you beyond clarifying what I’ve done below. Given that it’s just a duplication
   of Mail (2), my assumption is that it will be compatible with most (if not all)
   versions of CF7 that have Mail (2). [I don’t know if the plug-in author has changed
   this coding much, though, or if it will be changed in the future.]
 * As always, be sure you have a backup first! AND, you should also remember that
   you’ll have to add this code every time this plug-in updates, unless it’s a feature
   added later on.
 * ENJOY!!!
 * **admin.php** This is lines 293-308.
 *     ```
       add_meta_box( 'mail2div', __( 'Mail (2)', 'contact-form-7' ),
       		'wpcf7_mail_meta_box', null, 'mail_2', 'core',
       		array(
       			'id' => 'wpcf7-mail-2',
       			'name' => 'mail_2',
       			'use' => __( 'Use mail (2)', 'contact-form-7' ) ) );
   
       	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' ) ) );
   
       	add_meta_box( 'messagesdiv', __( 'Messages', 'contact-form-7' ),
       		'wpcf7_messages_meta_box', null, 'messages', 'core' );
       ```
   
 * **admin-functions.php** This is lines 110-184.
 *     ```
       $mail_2 = $properties['mail_2'];
   
       	$mail_2['active'] = ! empty( $_POST['wpcf7-mail-2-active'] );
   
       	if ( isset( $_POST['wpcf7-mail-2-subject'] ) ) {
       		$mail_2['subject'] = trim( $_POST['wpcf7-mail-2-subject'] );
       	}
   
       	if ( isset( $_POST['wpcf7-mail-2-sender'] ) ) {
       		$mail_2['sender'] = trim( $_POST['wpcf7-mail-2-sender'] );
       	}
   
       	if ( isset( $_POST['wpcf7-mail-2-body'] ) ) {
       		$mail_2['body'] = trim( $_POST['wpcf7-mail-2-body'] );
       	}
   
       	if ( isset( $_POST['wpcf7-mail-2-recipient'] ) ) {
       		$mail_2['recipient'] = trim( $_POST['wpcf7-mail-2-recipient'] );
       	}
   
       	if ( isset( $_POST['wpcf7-mail-2-additional-headers'] ) ) {
       		$mail_2['additional_headers'] = trim(
       			$_POST['wpcf7-mail-2-additional-headers'] );
       	}
   
       	if ( isset( $_POST['wpcf7-mail-2-attachments'] ) ) {
       		$mail_2['attachments'] = trim( $_POST['wpcf7-mail-2-attachments'] );
       	}
   
       	$mail_2['use_html'] = ! empty( $_POST['wpcf7-mail-2-use-html'] );
       	$mail_2['exclude_blank'] = ! empty( $_POST['wpcf7-mail-2-exclude-blank'] );
   
       	$properties['mail_2'] = $mail_2;
   
       	$mail_3 = $properties['mail_3'];
   
       	$mail_3['active'] = ! empty( $_POST['wpcf7-mail-3-active'] );
   
       	if ( isset( $_POST['wpcf7-mail-3-subject'] ) ) {
       		$mail_3['subject'] = trim( $_POST['wpcf7-mail-3-subject'] );
       	}
   
       	if ( isset( $_POST['wpcf7-mail-3-sender'] ) ) {
       		$mail_3['sender'] = trim( $_POST['wpcf7-mail-3-sender'] );
       	}
   
       	if ( isset( $_POST['wpcf7-mail-3-body'] ) ) {
       		$mail_3['body'] = trim( $_POST['wpcf7-mail-3-body'] );
       	}
   
       	if ( isset( $_POST['wpcf7-mail-3-recipient'] ) ) {
       		$mail_3['recipient'] = trim( $_POST['wpcf7-mail-3-recipient'] );
       	}
   
       	if ( isset( $_POST['wpcf7-mail-3-additional-headers'] ) ) {
       		$mail_3['additional_headers'] = trim(
       			$_POST['wpcf7-mail-3-additional-headers'] );
       	}
   
       	if ( isset( $_POST['wpcf7-mail-3-attachments'] ) ) {
       		$mail_3['attachments'] = trim( $_POST['wpcf7-mail-3-attachments'] );
       	}
   
       	$mail_3['use_html'] = ! empty( $_POST['wpcf7-mail-3-use-html'] );
       	$mail_3['exclude_blank'] = ! empty( $_POST['wpcf7-mail-3-exclude-blank'] );
   
       	$properties['mail_3'] = $mail_3;
   
       	foreach ( wpcf7_messages() as $key => $arr ) {
       		$field_name = 'wpcf7-message-' . strtr( $key, '_', '-' );
   
       		if ( isset( $_POST[$field_name] ) ) {
       			$properties['messages'][$key] = trim( $_POST[$field_name] );
       		}
       	}
       ```
   
 * **contact-form.php** This is lines 188-194.
 *     ```
       $properties = wp_parse_args( $properties, array(
       			'form' => '',
       			'mail' => array(),
       			'mail_2' => array(),
       			'mail_3' => array(),
       			'messages' => array(),
       			'additional_settings' => '' ) );
       ```
   
 * **contact-form-template.php** This is lines 5-18.
 *     ```
       public static function get_default( $prop = 'form' ) {
       		if ( 'form' == $prop ) {
       			$template = self::form();
       		} elseif ( 'mail' == $prop ) {
       			$template = self::mail();
       		} elseif ( 'mail_2' == $prop ) {
       			$template = self::mail_2();
       		} elseif ( 'mail_3' == $prop ) {
       			$template = self::mail_3();
       		} elseif ( 'messages' == $prop ) {
       			$template = self::messages();
       		} else {
       			$template = null;
       		}
       ```
   
 * AND, it’s also 63-120.
 *     ```
       public static function mail_2() {
       		$template = array(
       			'active' => false,
       			'subject' => '[your-subject]',
       			'sender' => sprintf( '%s <%s>',
       				get_bloginfo( 'name' ), self::from_email() ),
       			'body' =>
       				__( 'Message Body:', 'contact-form-7' )
       					. "\n" . '[your-message]' . "\n\n"
       				. '--' . "\n"
       				. sprintf( __( 'This e-mail was sent from a contact form on %1$s (%2$s)',
       					'contact-form-7' ), get_bloginfo( 'name' ), get_bloginfo( 'url' ) ),
       			'recipient' => '[your-email]',
       			'additional_headers' => sprintf( 'Reply-To: %s',
       				get_option( 'admin_email' ) ),
       			'attachments' => '',
       			'use_html' => 0,
       			'exclude_blank' => 0 );
   
       		return $template;
       	}
   
       	public static function mail_3() {
       		$template = array(
       			'active' => false,
       			'subject' => '[your-subject]',
       			'sender' => sprintf( '%s <%s>',
       				get_bloginfo( 'name' ), self::from_email() ),
       			'body' =>
       				__( 'Message Body:', 'contact-form-7' )
       					. "\n" . '[your-message]' . "\n\n"
       				. '--' . "\n"
       				. sprintf( __( 'This e-mail was sent from a contact form on %1$s (%2$s)',
       					'contact-form-7' ), get_bloginfo( 'name' ), get_bloginfo( 'url' ) ),
       			'recipient' => '[your-email]',
       			'additional_headers' => sprintf( 'Reply-To: %s',
       				get_option( 'admin_email' ) ),
       			'attachments' => '',
       			'use_html' => 0,
       			'exclude_blank' => 0 );
   
       		return $template;
       	}
   
       	public static function from_email() {
       		$admin_email = get_option( 'admin_email' );
       		$sitename = strtolower( $_SERVER['SERVER_NAME'] );
   
       		if ( 'localhost' == $sitename ) {
       			return $admin_email;
       		}
   
       		if ( substr( $sitename, 0, 4 ) == 'www.' ) {
       			$sitename = substr( $sitename, 4 );
       		}
   
       		if ( strpbrk( $admin_email, '@' ) == '@' . $sitename ) {
       			return $admin_email;
       		}
   
       		return 'wordpress@' . $sitename;
       	}
       ```
   
 * **edit-contact-form.php** This is lines 93-103.
 *     ```
       do_meta_boxes( null, 'mail_2', $post );
   
       do_action( 'wpcf7_admin_after_mail_2', $post );
   
       do_meta_boxes( null, 'mail_3', $post );
   
       do_action( 'wpcf7_admin_after_mail_3', $post );
   
       do_meta_boxes( null, 'messages', $post );
   
       do_action( 'wpcf7_admin_after_messages', $post );
       ```
   
 * **submission.php** This is lines 255-267.
 *     ```
       if ( $result ) {
       			$additional_mail = array();
   
       			if ( ( $mail_2 = $contact_form->prop( 'mail_2' ) ) && $mail_2['active'] ) {
       				$additional_mail['mail_2'] = $mail_2;
       			}
   
       			if ( ( $mail_3 = $contact_form->prop( 'mail_3' ) ) && $mail_3['active'] ) {
       				$additional_mail['mail_3'] = $mail_3;
       			}
   
       			$additional_mail = apply_filters( 'wpcf7_additional_mail',
       				$additional_mail, $contact_form );'
       ```
   
 * **upgrade.php** This is lines 37-46.
 *     ```
       if ( $post_id ) {
       			update_post_meta( $post_id, '_old_cf7_unit_id', $row->cf7_unit_id );
   
       			$metas = array( 'form', 'mail', 'mail_2', 'mail_3', 'messages', 'additional_settings' );
   
       			foreach ( $metas as $meta ) {
       				update_post_meta( $post_id, '_' . $meta,
       					wpcf7_normalize_newline_deep( maybe_unserialize( $row->{$meta} ) ) );
       			}
       		}
       ```
   
 * [https://wordpress.org/plugins/contact-form-7/](https://wordpress.org/plugins/contact-form-7/)

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

 *  [Neil Murray](https://wordpress.org/support/users/buzztone/)
 * (@buzztone)
 * [11 years, 4 months ago](https://wordpress.org/support/topic/adding-mail-3-coding-included/#post-5729953)
 * [@kylee6114](https://wordpress.org/support/users/kylee6114/) – I’d like to suggest
   that you consider incorporating your code into a plugin that extends Contact 
   Form 7. This would give people that need this option an easy way to implement
   this. Using a plugin means this can be done without adding to the existing code
   base size and interface complexity for people that don’t need this option.
 *  Thread Starter [kylee6114](https://wordpress.org/support/users/kylee6114/)
 * (@kylee6114)
 * [11 years, 4 months ago](https://wordpress.org/support/topic/adding-mail-3-coding-included/#post-5729959)
 * [@buzztone](https://wordpress.org/support/users/buzztone/) – As in, create my
   own plug-in (extension) to do this? If so, that’s more than I can take on right
   now; I was lucky to have time to dive into this… However, I’ll consider if it
   never gets added into CF7 altogether.
 * All told, though, there’s not a ton of coding added. Well over half of what I
   put above is contextual references, so the addition to CF7’s code base size is
   actually quite minimal. As an example, the coding added to **upgrade.php** is
   only: `, 'mail_3'`
    I included so much to help reduce confusion when other’s 
   looked into the coding, by offering them cues of what should come before and 
   after.
 * Thanks for the suggestion, though. If my schedule ever frees up to create and
   perpetually manage a plugin, I’ll consider taking up your suggestion myself. 
   Perhaps someone else {you? 😉 } can take that on if this isn’t included in a 
   future update.
 *  [Neil Murray](https://wordpress.org/support/users/buzztone/)
 * (@buzztone)
 * [11 years, 4 months ago](https://wordpress.org/support/topic/adding-mail-3-coding-included/#post-5729961)
 * > RE: Perhaps someone else {you? 😉 } can take that on if this isn’t included
   > in a future update.
 * I’d like to see someone else take this on as well. Could be a good learner plugin
   for someone. Ongoing management is another good learning opportunity.
 *  Thread Starter [kylee6114](https://wordpress.org/support/users/kylee6114/)
 * (@kylee6114)
 * [11 years, 4 months ago](https://wordpress.org/support/topic/adding-mail-3-coding-included/#post-5729962)
 * Sure is, buzztone =)
 *  [Chester_Tan.carve](https://wordpress.org/support/users/chester_tancarve/)
 * (@chester_tancarve)
 * [10 years, 8 months ago](https://wordpress.org/support/topic/adding-mail-3-coding-included/#post-5730319)
 * Good Day,
 * May I ask where these items can be found, I’ve found the admin but it seems to
   have a different format to the one above, though the admin-functions.php seems
   to be the same, sorry for asking, I’m still an intermediate level developer and
   I’m still learning a lot of factors.thank you for your time.
 * Sincerely yours
 * Chester

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

The topic ‘Adding Mail (3) – coding included’ is closed to new replies.

 * ![](https://ps.w.org/contact-form-7/assets/icon.svg?rev=2339255)
 * [Contact Form 7](https://wordpress.org/plugins/contact-form-7/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/contact-form-7/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/contact-form-7/)
 * [Active Topics](https://wordpress.org/support/plugin/contact-form-7/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/contact-form-7/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/contact-form-7/reviews/)

## Tags

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

 * 5 replies
 * 3 participants
 * Last reply from: [Chester_Tan.carve](https://wordpress.org/support/users/chester_tancarve/)
 * Last activity: [10 years, 8 months ago](https://wordpress.org/support/topic/adding-mail-3-coding-included/#post-5730319)
 * Status: not a support question