Skip to content

Commit

Permalink
Feature - Multiple email recipient
Browse files Browse the repository at this point in the history
  • Loading branch information
Shiva Poudel committed Apr 12, 2018
1 parent 72c9560 commit 4562da3
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 51 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
== Changelog ==

= 1.1.3 - 12-04-2018 =
* Feature - Multiple email recipient.
* Fix - Per page entries in list table.
* Fix - Clone field next to it not at last.
* Fix - Empty field ID if meta key is renamed.
Expand Down
103 changes: 52 additions & 51 deletions includes/class-evf-form-task.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ public function do_task( $entry ) {
// Success - send email notification.
$this->entry_email( $this->form_fields, $entry, $form_data, $entry_id, 'entry' );

$_POST['evf_success'] = true;

// Pass completed and formatted fields in POST.
$_POST['everest-forms']['complete'] = $this->form_fields;

Expand Down Expand Up @@ -308,77 +310,76 @@ public function entry_email( $fields, $entry, $form_data, $entry_id, $context =

$email_notifications = isset( $form_data['settings']['email'] ) ? $form_data['settings']['email'] : array();

if ( empty( $email_notifications['evf_to_email'] ) ) {
return;
}
if ( empty( $email_notifications['evf_to_email'] ) ) {
return;
}

$form_fields = isset( $form_data['form_fields'] ) ? $form_data['form_fields'] : array();
$form_fields = isset( $form_data['form_fields'] ) ? $form_data['form_fields'] : array();

$data_html = '';
$data_html = '';

foreach ( $form_fields as $field_key => $field ) {
foreach ( $form_fields as $field_key => $field ) {

$field_type = isset( $field['type'] ) ? $field['type'] : '';
$field_type = isset( $field['type'] ) ? $field['type'] : '';

$label = isset( $field['label'] ) ? $field['label'] : '';
$label = isset( $field['label'] ) ? $field['label'] : '';

$field_value = isset( $entry['form_fields'][ $field_key ] ) ? $entry['form_fields'][ $field_key ] : '';
$field_value = isset( $entry['form_fields'][ $field_key ] ) ? $entry['form_fields'][ $field_key ] : '';

if( $field_type == 'email' ){
$user_email = $field_value;
}
if ( ! empty( $field_type ) ) {
if( $field_type == 'email' ){
$user_email = $field_value;
}
if ( ! empty( $field_type ) ) {

$process_field_email = apply_filters( 'everest_forms_entry_email_' . $field_type, true );
$process_field_email = apply_filters( 'everest_forms_entry_email_' . $field_type, true );

if ( $process_field_email ) {
if ( $process_field_email ) {

if ( is_array( $field_value ) ) {
$field_value = implode( ',', $field_value );
}
$data_html .= $label . ' : ' . $field_value . PHP_EOL;
if ( is_array( $field_value ) ) {
$field_value = implode( ',', $field_value );
}
$data_html .= $label . ' : ' . $field_value . PHP_EOL;
}
}
}

$email = array();
$email = array();

$email['evf_email_subject'] = ! empty( $email_notifications['evf_email_subject'] ) ? $email_notifications['evf_email_subject'] : sprintf( _x( 'New %s Entry', 'Form name', 'everest-forms' ), $form_data['settings']['form_title'] );
$email['evf_from_email'] = ! empty( $email_notifications['evf_from_email'] ) ? $email_notifications['evf_from_email'] : evf_sender_address();
$email['evf_from_name'] = ! empty( $email_notifications['evf_from_name'] ) ? $email_notifications['evf_from_name'] : evf_sender_name();
$email['evf_to_email'] = ! empty( $email_notifications['evf_to_email'] ) ? $email_notifications['evf_to_email'] : false;
$email['evf_email_header'] = ! empty( $email_notifications['evf_email_header'] ) ? $email_notifications['evf_email_header'] : '';
$email['evf_from_email'] = ! empty( $email_notifications['evf_from_email'] ) ? $email_notifications['evf_from_email'] : evf_sender_address();
$email['evf_from_name'] = ! empty( $email_notifications['evf_from_name'] ) ? $email_notifications['evf_from_name'] : evf_sender_name();
$email['evf_email_header'] = ! empty( $email_notifications['evf_email_header'] ) ? $email_notifications['evf_email_header'] : '';
$email['evf_email_subject'] = ! empty( $email_notifications['evf_email_subject'] ) ? $email_notifications['evf_email_subject'] : sprintf( _x( 'New %s Entry', 'Form name', 'everest-forms' ), $form_data['settings']['form_title'] );
$email['evf_to_email'] = explode( ',', apply_filters( 'everest_forms_process_smart_tags', $email_notifications['evf_to_email'], $form_data, $fields, $this->entry_id ) );
$email['evf_to_email'] = array_map( 'sanitize_email', $email['evf_to_email'] );

if ( ! empty( $email_notifications['evf_email_message'] ) ) {
if ( trim( '{all_fields}' ) == $email_notifications['evf_email_message'] ){
$email['evf_email_message'] = $data_html;
}
else {
$message = str_replace( "{all_fields}", $data_html, $email_notifications['evf_email_message'] );
$email['evf_email_message'] = $message;
}
if ( ! empty( $email_notifications['evf_email_message'] ) ) {
if ( trim( '{all_fields}' ) == $email_notifications['evf_email_message'] ){
$email['evf_email_message'] = $data_html;
}
else {
$message = str_replace( "{all_fields}", $data_html, $email_notifications['evf_email_message'] );
$email['evf_email_message'] = $message;
}
}

// Create new email.
$emails = new EVF_Emails;
$emails->__set( 'form_data', $form_data );
$emails->__set( 'fields', $fields );
$emails->__set( 'entry_id', $this->entry_id );
$emails->__set( 'from_name', $email['evf_from_name'] );
$emails->__set( 'from_address', $email['evf_from_email'] );
$emails->__set( 'headers', $email['evf_email_header'] );
$emails->__set( 'reply_to', isset( $user_email ) ? $user_email : $email['evf_from_email'] );

// Go.
$status = $emails->send( trim( $email['evf_to_email'] ), $email['evf_email_subject'], $email['evf_email_message'] );

$_POST['evf_success'] = isset( $status ) ? true : false;

return $status;

// Create new email.
$emails = new EVF_Emails();
$emails->__set( 'form_data', $form_data );
$emails->__set( 'fields', $fields );
$emails->__set( 'entry_id', $this->entry_id );
$emails->__set( 'from_name', $email['evf_from_name'] );
$emails->__set( 'from_address', $email['evf_from_email'] );
$emails->__set( 'headers', $email['evf_email_header'] );
$emails->__set( 'reply_to', isset( $user_email ) ? $user_email : $email['evf_from_email'] );

// Go.
if ( ! empty( $email['evf_to_email'] ) ) {
foreach ( $email['evf_to_email'] as $address ) {
$emails->send( trim( $address ), $email['evf_email_subject'], $email['evf_email_message'] );
}
}
}


/**
* Saves entry to database.
*
Expand Down
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ Yes, the plugin is designed to work with any themes that have been coded followi
== Changelog ==

= 1.1.3 - 12-04-2018 =
* Feature - Multiple email recipient.
* Fix - Per page entries in list table.
* Fix - Clone field next to it not at last.
* Fix - Empty field ID if meta key is renamed.
Expand Down

0 comments on commit 4562da3

Please sign in to comment.