| @@ -8,94 +8,94 @@ | ||
| 8 | 8 | */ |
| 9 | 9 | class FrmEmail { |
| 10 | 10 | |
| 11 | 11 | /** |
| 12 | - * @var string | |
| 12 | + * @var string $email_key | |
| 13 | 13 | */ |
| 14 | 14 | private $email_key = ''; |
| 15 | 15 | |
| 16 | 16 | /** |
| 17 | - * @var array | |
| 17 | + * @var array $to | |
| 18 | 18 | */ |
| 19 | 19 | private $to = array(); |
| 20 | 20 | |
| 21 | 21 | /** |
| 22 | - * @var array | |
| 22 | + * @var array $cc | |
| 23 | 23 | */ |
| 24 | 24 | private $cc = array(); |
| 25 | 25 | |
| 26 | 26 | /** |
| 27 | - * @var array | |
| 27 | + * @var array $bcc | |
| 28 | 28 | */ |
| 29 | 29 | private $bcc = array(); |
| 30 | 30 | |
| 31 | 31 | /** |
| 32 | - * @var string | |
| 32 | + * @var string $from | |
| 33 | 33 | */ |
| 34 | 34 | private $from = ''; |
| 35 | 35 | |
| 36 | 36 | /** |
| 37 | - * @var string | |
| 37 | + * @var string $reply_to | |
| 38 | 38 | */ |
| 39 | 39 | private $reply_to = ''; |
| 40 | 40 | |
| 41 | 41 | /** |
| 42 | - * @var string | |
| 42 | + * @var string $subject | |
| 43 | 43 | */ |
| 44 | 44 | private $subject = ''; |
| 45 | 45 | |
| 46 | 46 | /** |
| 47 | - * @var string | |
| 47 | + * @var string $message | |
| 48 | 48 | */ |
| 49 | 49 | private $message = ''; |
| 50 | 50 | |
| 51 | 51 | /** |
| 52 | - * @var array | |
| 52 | + * @var array $attachments | |
| 53 | 53 | */ |
| 54 | 54 | private $attachments = array(); |
| 55 | 55 | |
| 56 | 56 | /** |
| 57 | - * @var bool | |
| 57 | + * @var bool $is_plain_text | |
| 58 | 58 | */ |
| 59 | 59 | private $is_plain_text = false; |
| 60 | 60 | |
| 61 | 61 | /** |
| 62 | - * @var bool | |
| 62 | + * @var bool $is_single_recipient | |
| 63 | 63 | */ |
| 64 | 64 | private $is_single_recipient = false; |
| 65 | 65 | |
| 66 | 66 | /** |
| 67 | - * @var bool | |
| 67 | + * @var bool $include_user_info | |
| 68 | 68 | */ |
| 69 | 69 | private $include_user_info = false; |
| 70 | 70 | |
| 71 | 71 | /** |
| 72 | - * @var string | |
| 72 | + * @var string $charset | |
| 73 | 73 | */ |
| 74 | 74 | private $charset = ''; |
| 75 | 75 | |
| 76 | 76 | /** |
| 77 | - * @var string | |
| 77 | + * @var string $content_type | |
| 78 | 78 | */ |
| 79 | 79 | private $content_type = 'text/html'; |
| 80 | 80 | |
| 81 | 81 | /** |
| 82 | - * @var array | |
| 82 | + * @var array $settings | |
| 83 | 83 | */ |
| 84 | 84 | private $settings = array(); |
| 85 | 85 | |
| 86 | 86 | /** |
| 87 | - * @var stdClass | |
| 87 | + * @var stdClass $entry | |
| 88 | 88 | */ |
| 89 | 89 | private $entry; |
| 90 | 90 | |
| 91 | 91 | /** |
| 92 | - * @var stdClass | |
| 92 | + * @var stdClass $form | |
| 93 | 93 | */ |
| 94 | 94 | private $form; |
| 95 | 95 | |
| 96 | 96 | /** |
| 97 | - * @var int | |
| 97 | + * @var int $action_id | |
| 98 | 98 | */ |
| 99 | 99 | private $action_id = 0; |
| 100 | 100 | |
| 101 | 101 | /** |
| @@ -216,9 +216,9 @@ | ||
| 216 | 216 | * |
| 217 | 217 | * @since 2.03.04 |
| 218 | 218 | * |
| 219 | 219 | * @param string $recipients |
| 220 | - * @param array $user_id_args | |
| 220 | + * @param array $user_id_args | |
| 221 | 221 | * |
| 222 | 222 | * @return array |
| 223 | 223 | */ |
| 224 | 224 | private function prepare_additional_recipients( $recipients, $user_id_args ) { |
| @@ -240,9 +240,9 @@ | ||
| 240 | 240 | * @return void |
| 241 | 241 | */ |
| 242 | 242 | private function set_from( $user_id_args ) { |
| 243 | 243 | if ( empty( $this->settings['from'] ) ) { |
| 244 | - $from = FrmEmailHelper::get_default_from_email(); | |
| 244 | + $from = get_option( 'admin_email' ); | |
| 245 | 245 | } else { |
| 246 | 246 | $from = $this->prepare_email_setting( $this->settings['from'], $user_id_args ); |
| 247 | 247 | } |
| 248 | 248 | |
| @@ -280,15 +280,11 @@ | ||
| 280 | 280 | * |
| 281 | 281 | * @return void |
| 282 | 282 | */ |
| 283 | 283 | private function set_is_plain_text() { |
| 284 | - if ( empty( $this->settings['email_style'] ) ) { | |
| 285 | - // If `email_style` isn't set, use the `plain_text` checkbox. | |
| 286 | - $this->is_plain_text = ! empty( $this->settings['plain_text'] ); | |
| 287 | - return; | |
| 284 | + if ( $this->settings['plain_text'] ) { | |
| 285 | + $this->is_plain_text = true; | |
| 288 | 286 | } |
| 289 | - | |
| 290 | - $this->is_plain_text = 'plain' === $this->settings['email_style']; | |
| 291 | 287 | } |
| 292 | 288 | |
| 293 | 289 | /** |
| 294 | 290 | * Set the include_user_info property |
| @@ -308,8 +304,9 @@ | ||
| 308 | 304 | * Set the is_single_recipient property |
| 309 | 305 | * |
| 310 | 306 | * @since 2.03.04 |
| 311 | 307 | * |
| 308 | + * @param $action | |
| 312 | 309 | * @param object $action |
| 313 | 310 | * |
| 314 | 311 | * @return void |
| 315 | 312 | */ |
| @@ -389,31 +386,28 @@ | ||
| 389 | 386 | private function set_message() { |
| 390 | 387 | $this->message = $this->settings['email_message']; |
| 391 | 388 | |
| 392 | 389 | if ( ! $this->is_plain_text ) { |
| 393 | - // The decode is to support [default-html] shortcodes. | |
| 394 | - $this->message = html_entity_decode( $this->message ); | |
| 390 | + $this->message = html_entity_decode( $this->message ); // The decode is to support [default-html] shortcodes. | |
| 395 | 391 | } |
| 396 | 392 | |
| 397 | - $this->message = FrmFieldsHelper::basic_replace_shortcodes( $this->message, $this->form, $this->entry ); | |
| 393 | + $this->message = FrmFieldsHelper::basic_replace_shortcodes( $this->message, $this->form, $this->entry ); | |
| 394 | + | |
| 398 | 395 | $prev_mail_body = $this->message; |
| 399 | - | |
| 400 | - // Make a copy to prevent changes by reference. | |
| 401 | - $pass_entry = clone $this->entry; | |
| 402 | - $mail_body = FrmEntriesHelper::replace_default_message( | |
| 396 | + $pass_entry = clone $this->entry; // make a copy to prevent changes by reference | |
| 397 | + $mail_body = FrmEntriesHelper::replace_default_message( | |
| 403 | 398 | $prev_mail_body, |
| 404 | 399 | array( |
| 405 | - 'id' => $this->entry->id, | |
| 406 | - 'entry' => $pass_entry, | |
| 407 | - 'plain_text' => $this->is_plain_text, | |
| 408 | - 'user_info' => $this->include_user_info, | |
| 409 | - 'table_style' => $this->settings['email_style'], | |
| 400 | + 'id' => $this->entry->id, | |
| 401 | + 'entry' => $pass_entry, | |
| 402 | + 'plain_text' => $this->is_plain_text, | |
| 403 | + 'user_info' => $this->include_user_info, | |
| 410 | 404 | ) |
| 411 | 405 | ); |
| 412 | 406 | |
| 413 | 407 | // Add the user info if it isn't already included |
| 414 | 408 | if ( $this->include_user_info && $prev_mail_body === $mail_body ) { |
| 415 | - $data = $this->entry->description; | |
| 409 | + $data = $this->entry->description; | |
| 416 | 410 | $mail_body .= "\r\n\r\n" . __( 'User Information', 'formidable' ) . "\r\n"; |
| 417 | 411 | $this->maybe_add_ip( $mail_body ); |
| 418 | 412 | $mail_body .= __( 'User-Agent (Browser/OS)', 'formidable' ) . ': ' . FrmEntriesHelper::get_browser( $data['browser'] ) . "\r\n"; |
| 419 | 413 | $mail_body .= __( 'Referrer', 'formidable' ) . ': ' . $data['referrer'] . "\r\n"; |
| @@ -420,11 +414,12 @@ | ||
| 420 | 414 | } |
| 421 | 415 | |
| 422 | 416 | $this->message = $mail_body; |
| 423 | 417 | |
| 418 | + $this->message = do_shortcode( $this->message ); | |
| 419 | + | |
| 424 | 420 | if ( $this->is_plain_text ) { |
| 425 | 421 | $this->message = wp_specialchars_decode( strip_tags( $this->message ), ENT_QUOTES ); |
| 426 | - $this->message = str_replace( ' ', '', $this->message ); | |
| 427 | 422 | } else { |
| 428 | 423 | $this->add_autop(); |
| 429 | 424 | } |
| 430 | 425 | |
| @@ -516,10 +511,11 @@ | ||
| 516 | 511 | */ |
| 517 | 512 | private function has_recipients() { |
| 518 | 513 | if ( empty( $this->to ) && empty( $this->cc ) && empty( $this->bcc ) ) { |
| 519 | 514 | return false; |
| 515 | + } else { | |
| 516 | + return true; | |
| 520 | 517 | } |
| 521 | - return true; | |
| 522 | 518 | } |
| 523 | 519 | |
| 524 | 520 | /** |
| 525 | 521 | * Send an email |
| @@ -611,9 +607,9 @@ | ||
| 611 | 607 | * Get the userID field ID and key for email settings |
| 612 | 608 | * |
| 613 | 609 | * @since 2.03.04 |
| 614 | 610 | * |
| 615 | - * @param int $form_id | |
| 611 | + * @param $form_id | |
| 616 | 612 | * |
| 617 | 613 | * @return array |
| 618 | 614 | */ |
| 619 | 615 | private function get_user_id_args( $form_id ) { |
| @@ -635,9 +631,9 @@ | ||
| 635 | 631 | * |
| 636 | 632 | * @since 2.03.04 |
| 637 | 633 | * |
| 638 | 634 | * @param string $value |
| 639 | - * @param array $user_id_args | |
| 635 | + * @param array $user_id_args | |
| 640 | 636 | * |
| 641 | 637 | * @return string |
| 642 | 638 | */ |
| 643 | 639 | private function prepare_email_setting( $value, $user_id_args ) { |
| @@ -694,24 +690,24 @@ | ||
| 694 | 690 | |
| 695 | 691 | if ( is_email( $val ) ) { |
| 696 | 692 | // If a plain email is used, no formatting is needed |
| 697 | 693 | continue; |
| 698 | - } | |
| 694 | + } else { | |
| 695 | + $parts = explode( ' ', $val ); | |
| 696 | + $email = end( $parts ); | |
| 699 | 697 | |
| 700 | - $parts = explode( ' ', $val ); | |
| 701 | - $email = end( $parts ); | |
| 702 | - | |
| 703 | - if ( is_email( $email ) ) { | |
| 704 | - // If user enters a name and email | |
| 705 | - $name = trim( str_replace( $email, '', $val ) ); | |
| 706 | - } else { | |
| 707 | - // If user enters a name without an email | |
| 708 | - unset( $recipients[ $key ] ); | |
| 709 | - continue; | |
| 698 | + if ( is_email( $email ) ) { | |
| 699 | + // If user enters a name and email | |
| 700 | + $name = trim( str_replace( $email, '', $val ) ); | |
| 701 | + } else { | |
| 702 | + // If user enters a name without an email | |
| 703 | + unset( $recipients[ $key ] ); | |
| 704 | + continue; | |
| 705 | + } | |
| 710 | 706 | } |
| 711 | 707 | |
| 712 | 708 | $recipients[ $key ] = $this->format_from_email( $name, $email ); |
| 713 | - }//end foreach | |
| 709 | + } | |
| 714 | 710 | |
| 715 | 711 | return $recipients; |
| 716 | 712 | } |
| 717 | 713 | |
| @@ -761,9 +757,9 @@ | ||
| 761 | 757 | $reply_to = trim( $reply_to ); |
| 762 | 758 | |
| 763 | 759 | if ( ! is_email( $reply_to ) ) { |
| 764 | 760 | list( $name, $email ) = $this->get_name_and_email_for_sender( $reply_to ); |
| 765 | - $reply_to = $this->format_from_email( $name, $email ); | |
| 761 | + $reply_to = $this->format_from_email( $name, $email ); | |
| 766 | 762 | } |
| 767 | 763 | |
| 768 | 764 | return $reply_to; |
| 769 | 765 | } |
| @@ -859,10 +855,10 @@ | ||
| 859 | 855 | ); |
| 860 | 856 | |
| 861 | 857 | // Remove phone number from to addresses |
| 862 | 858 | unset( $this->to[ $key ] ); |
| 863 | - }//end if | |
| 864 | - }//end foreach | |
| 859 | + } | |
| 860 | + } | |
| 865 | 861 | } |
| 866 | 862 | |
| 867 | 863 | /** |
| 868 | 864 | * Package an array of FrmEmail properties |
| @@ -883,9 +879,8 @@ | ||
| 883 | 879 | 'attachments' => $this->attachments, |
| 884 | 880 | 'plain_text' => $this->is_plain_text, |
| 885 | 881 | 'form' => $this->form, |
| 886 | 882 | 'entry' => $this->entry, |
| 887 | - 'email_style' => $this->settings['email_style'], | |
| 888 | 883 | ); |
| 889 | 884 | } |
| 890 | 885 | |
| 891 | 886 | /** |