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} ) ) ); } }
- The topic ‘Adding Mail (3) – coding included’ is closed to new replies.