PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.8
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.8
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
← All changes | classes/models/FrmEmail.php +122 -115 6.296.8 View file →
@@ -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 /**
@@ -175,9 +175,9 @@
175 175 $to = apply_filters( 'frm_to_email', $to, $values, $this->form->id, $args );
176 176
177 177 $this->to = array_unique( (array) $to );
178 178
179 - if ( ! $this->to ) {
179 + if ( empty( $this->to ) ) {
180 180 return;
181 181 }
182 182
183 183 $this->handle_phone_numbers();
@@ -223,11 +223,13 @@
223 223 */
224 224 private function prepare_additional_recipients( $recipients, $user_id_args ) {
225 225 $recipients = $this->prepare_email_setting( $recipients, $user_id_args );
226 226 $recipients = $this->explode_emails( $recipients );
227 +
227 228 $recipients = array_unique( (array) $recipients );
229 + $recipients = $this->format_recipients( $recipients );
228 230
229 - return $this->format_recipients( $recipients );
231 + return $recipients;
230 232 }
231 233
232 234 /**
233 235 * Set the From addresses
@@ -234,14 +236,13 @@
234 236 *
235 237 * @since 2.03.04
236 238 *
237 239 * @param array $user_id_args
238 - *
239 240 * @return void
240 241 */
241 242 private function set_from( $user_id_args ) {
242 243 if ( empty( $this->settings['from'] ) ) {
243 - $from = FrmEmailHelper::get_default_from_email();
244 + $from = get_option( 'admin_email' );
244 245 } else {
245 246 $from = $this->prepare_email_setting( $this->settings['from'], $user_id_args );
246 247 }
247 248
@@ -279,15 +280,11 @@
279 280 *
280 281 * @return void
281 282 */
282 283 private function set_is_plain_text() {
283 - if ( empty( $this->settings['email_style'] ) ) {
284 - // If `email_style` isn't set, use the `plain_text` checkbox.
285 - $this->is_plain_text = ! empty( $this->settings['plain_text'] );
286 - return;
284 + if ( $this->settings['plain_text'] ) {
285 + $this->is_plain_text = true;
287 286 }
288 -
289 - $this->is_plain_text = 'plain' === $this->settings['email_style'];
290 287 }
291 288
292 289 /**
293 290 * Set the include_user_info property
@@ -392,9 +389,10 @@
392 389 // The decode is to support [default-html] shortcodes.
393 390 $this->message = html_entity_decode( $this->message );
394 391 }
395 392
396 - $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 +
397 395 $prev_mail_body = $this->message;
398 396
399 397 // Make a copy to prevent changes by reference.
400 398 $pass_entry = clone $this->entry;
@@ -400,19 +398,18 @@
400 398 $pass_entry = clone $this->entry;
401 399 $mail_body = FrmEntriesHelper::replace_default_message(
402 400 $prev_mail_body,
403 401 array(
404 - 'id' => $this->entry->id,
405 - 'entry' => $pass_entry,
406 - 'plain_text' => $this->is_plain_text,
407 - 'user_info' => $this->include_user_info,
408 - 'table_style' => $this->settings['email_style'],
402 + 'id' => $this->entry->id,
403 + 'entry' => $pass_entry,
404 + 'plain_text' => $this->is_plain_text,
405 + 'user_info' => $this->include_user_info,
409 406 )
410 407 );
411 408
412 409 // Add the user info if it isn't already included
413 410 if ( $this->include_user_info && $prev_mail_body === $mail_body ) {
414 - $data = $this->entry->description;
411 + $data = $this->entry->description;
415 412 $mail_body .= "\r\n\r\n" . __( 'User Information', 'formidable' ) . "\r\n";
416 413 $this->maybe_add_ip( $mail_body );
417 414 $mail_body .= __( 'User-Agent (Browser/OS)', 'formidable' ) . ': ' . FrmEntriesHelper::get_browser( $data['browser'] ) . "\r\n";
418 415 $mail_body .= __( 'Referrer', 'formidable' ) . ': ' . $data['referrer'] . "\r\n";
@@ -419,11 +416,12 @@
419 416 }
420 417
421 418 $this->message = $mail_body;
422 419
420 + $this->message = do_shortcode( $this->message );
421 +
423 422 if ( $this->is_plain_text ) {
424 423 $this->message = wp_specialchars_decode( strip_tags( $this->message ), ENT_QUOTES );
425 - $this->message = str_replace( ' ', '', $this->message );
426 424 } else {
427 425 $this->add_autop();
428 426 }
429 427
@@ -436,10 +434,9 @@
436 434 * @return void
437 435 */
438 436 private function add_autop() {
439 437 $message = $this->message;
440 - preg_match( '/<body[^>]*>([\s\S]*?)<\/body>/', $message, $match );
441 -
438 + $result = preg_match( '/<body[^>]*>([\s\S]*?)<\/body>/', $message, $match );
442 439 if ( ! empty( $match[1] ) ) {
443 440 $this->message = str_replace( $match[1], trim( wpautop( $match[1] ) ), $message );
444 441 } else {
445 442 $this->message = trim( wpautop( $message ) );
@@ -484,24 +481,28 @@
484 481 * @return bool|mixed|void
485 482 */
486 483 public function should_send() {
487 484 if ( ! $this->has_recipients() ) {
488 - return false;
485 + $send = false;
486 + } else {
487 +
488 + $filter_args = array(
489 + 'message' => $this->message,
490 + 'subject' => $this->subject,
491 + 'recipient' => $this->to,
492 + 'header' => $this->package_header(),
493 + );
494 +
495 + /**
496 + * Stop an email based on the message, subject, recipient,
497 + * or any information included in the email header
498 + *
499 + * @since 2.2.8
500 + */
501 + $send = apply_filters( 'frm_send_email', true, $filter_args );
489 502 }
490 503
491 - $filter_args = array(
492 - 'message' => $this->message,
493 - 'subject' => $this->subject,
494 - 'recipient' => $this->to,
495 - 'header' => $this->package_header(),
496 - );
497 - /**
498 - * Stop an email based on the message, subject, recipient,
499 - * or any information included in the email header
500 - *
501 - * @since 2.2.8
502 - */
503 - return apply_filters( 'frm_send_email', true, $filter_args );
504 + return $send;
504 505 }
505 506
506 507 /**
507 508 * Check if an email has any recipients
@@ -510,9 +511,13 @@
510 511 *
511 512 * @return bool
512 513 */
513 514 private function has_recipients() {
514 - return $this->to || $this->cc || $this->bcc;
515 + if ( empty( $this->to ) && empty( $this->cc ) && empty( $this->bcc ) ) {
516 + return false;
517 + } else {
518 + return true;
519 + }
515 520 }
516 521
517 522 /**
518 523 * Send an email
@@ -525,9 +530,8 @@
525 530 $this->remove_buddypress_filters();
526 531 $this->add_mandrill_filter();
527 532
528 533 $sent = false;
529 -
530 534 if ( count( $this->to ) > 1 && $this->is_single_recipient ) {
531 535 foreach ( $this->to as $recipient ) {
532 536 $sent = $this->send_single( $recipient );
533 537 }
@@ -559,15 +563,15 @@
559 563 )
560 564 );
561 565
562 566 $subject = $this->encode_subject( $this->subject );
563 - $sent = wp_mail( $recipient, $subject, $this->message, $header, $this->attachments );
564 567
568 + $sent = wp_mail( $recipient, $subject, $this->message, $header, $this->attachments );
569 +
565 570 if ( ! $sent ) {
566 571 if ( is_array( $header ) ) {
567 572 $header = implode( "\r\n", $header );
568 573 }
569 -
570 574 $recipient = implode( ',', (array) $recipient );
571 575 $sent = mail( $recipient, $subject, $this->message, $header );
572 576 }
573 577
@@ -585,13 +589,13 @@
585 589 */
586 590 private function package_header() {
587 591 $header = array();
588 592
589 - if ( $this->cc ) {
593 + if ( ! empty( $this->cc ) ) {
590 594 $header[] = 'CC: ' . implode( ',', $this->cc );
591 595 }
592 596
593 - if ( $this->bcc ) {
597 + if ( ! empty( $this->bcc ) ) {
594 598 $header[] = 'BCC: ' . implode( ',', $this->bcc );
595 599 }
596 600
597 601 $header[] = 'From: ' . $this->from;
@@ -616,9 +620,8 @@
616 620 'field_key' => '',
617 621 );
618 622
619 623 $user_id_args['field_id'] = FrmEmailHelper::get_user_id_field_for_form( $form_id );
620 -
621 624 if ( $user_id_args['field_id'] ) {
622 625 $user_id_args['field_key'] = FrmField::get_key_by_id( $user_id_args['field_id'] );
623 626 }
624 627
@@ -635,11 +638,11 @@
635 638 *
636 639 * @return string
637 640 */
638 641 private function prepare_email_setting( $value, $user_id_args ) {
639 - if ( str_contains( $value, '[' . $user_id_args['field_id'] . ']' ) ) {
642 + if ( strpos( $value, '[' . $user_id_args['field_id'] . ']' ) !== false ) {
640 643 $value = str_replace( '[' . $user_id_args['field_id'] . ']', '[' . $user_id_args['field_id'] . ' show="user_email"]', $value );
641 - } elseif ( str_contains( $value, '[' . $user_id_args['field_key'] . ']' ) ) {
644 + } elseif ( strpos( $value, '[' . $user_id_args['field_key'] . ']' ) !== false ) {
642 645 $value = str_replace( '[' . $user_id_args['field_key'] . ']', '[' . $user_id_args['field_key'] . ' show="user_email"]', $value );
643 646 }
644 647
645 648 $value = FrmFieldsHelper::basic_replace_shortcodes( $value, $this->form, $this->entry );
@@ -645,10 +648,11 @@
645 648 $value = FrmFieldsHelper::basic_replace_shortcodes( $value, $this->form, $this->entry );
646 649
647 650 // Remove brackets and add a space in case there isn't one
648 651 $value = str_replace( '<', ' ', $value );
652 + $value = str_replace( array( '"', '>' ), '', $value );
649 653
650 - return str_replace( array( '"', '>' ), '', $value );
654 + return $value;
651 655 }
652 656
653 657 /**
654 658 * Extract the emails from cc and bcc. Allow separation by , or ;.
@@ -657,13 +661,19 @@
657 661 * @since 2.03.04
658 662 *
659 663 * @param string $emails
660 664 *
661 - * @return array|string Emails.
665 + * @return array|string $emails
662 666 */
663 667 private function explode_emails( $emails ) {
664 - $emails = $emails ? preg_split( '/(,|;)/', $emails ) : '';
665 - return is_array( $emails ) ? array_map( 'trim', $emails ) : trim( $emails );
668 + $emails = ( ! empty( $emails ) ? preg_split( '/(,|;)/', $emails ) : '' );
669 + if ( is_array( $emails ) ) {
670 + $emails = array_map( 'trim', $emails );
671 + } else {
672 + $emails = trim( $emails );
673 + }
674 +
675 + return $emails;
666 676 }
667 677
668 678 /**
669 679 * Format the recipients( to, cc, bcc)
@@ -672,9 +682,9 @@
672 682 *
673 683 * @return array
674 684 */
675 685 private function format_recipients( $recipients ) {
676 - if ( ! $recipients ) {
686 + if ( empty( $recipients ) ) {
677 687 return $recipients;
678 688 }
679 689
680 690 foreach ( $recipients as $key => $val ) {
@@ -682,22 +692,22 @@
682 692
683 693 if ( is_email( $val ) ) {
684 694 // If a plain email is used, no formatting is needed
685 695 continue;
686 - }
696 + } else {
697 + $parts = explode( ' ', $val );
698 + $email = end( $parts );
687 699
688 - $parts = explode( ' ', $val );
689 - $email = end( $parts );
690 -
691 - if ( ! is_email( $email ) ) {
692 - // If user enters a name without an email
693 - unset( $recipients[ $key ] );
694 - continue;
700 + if ( is_email( $email ) ) {
701 + // If user enters a name and email
702 + $name = trim( str_replace( $email, '', $val ) );
703 + } else {
704 + // If user enters a name without an email
705 + unset( $recipients[ $key ] );
706 + continue;
707 + }
695 708 }
696 709
697 - // If user enters a name and email
698 - $name = trim( str_replace( $email, '', $val ) );
699 -
700 710 $recipients[ $key ] = $this->format_from_email( $name, $email );
701 711 }//end foreach
702 712
703 713 return $recipients;
@@ -720,14 +730,14 @@
720 730 } else {
721 731 list( $from_name, $from_email ) = $this->get_name_and_email_for_sender( $from );
722 732 }
723 733
724 - // If sending the email from a yahoo address, change it to the WordPress default
725 - if ( str_contains( $from_email, '@yahoo.com' ) ) {
734 + // if sending the email from a yahoo address, change it to the WordPress default
735 + if ( strpos( $from_email, '@yahoo.com' ) ) {
736 +
726 737 // Get the site domain and get rid of www.
727 738 $sitename = strtolower( FrmAppHelper::get_server_value( 'SERVER_NAME' ) );
728 -
729 - if ( str_starts_with( $sitename, 'www.' ) ) {
739 + if ( substr( $sitename, 0, 4 ) === 'www.' ) {
730 740 $sitename = substr( $sitename, 4 );
731 741 }
732 742
733 743 $from_email = 'wordpress@' . $sitename;
@@ -749,9 +759,9 @@
749 759 $reply_to = trim( $reply_to );
750 760
751 761 if ( ! is_email( $reply_to ) ) {
752 762 list( $name, $email ) = $this->get_name_and_email_for_sender( $reply_to );
753 - $reply_to = $this->format_from_email( $name, $email );
763 + $reply_to = $this->format_from_email( $name, $email );
754 764 }
755 765
756 766 return $reply_to;
757 767 }
@@ -766,10 +776,9 @@
766 776 * @return string
767 777 */
768 778 private function get_email_from_name( $name ) {
769 779 $email = trim( trim( $name, '>' ), '<' );
770 -
771 - if ( str_contains( $email, '<' ) ) {
780 + if ( strpos( $email, '<' ) !== false ) {
772 781 $parts = explode( '<', $email );
773 782 $email = trim( $parts[1], '>' );
774 783 }
775 784
@@ -804,13 +813,15 @@
804 813 * @since 3.0.06
805 814 *
806 815 * @param string $name
807 816 * @param string $email
808 - *
809 - * @return string
810 817 */
811 818 private function format_from_email( $name, $email ) {
812 - return '' !== $name ? $name . ' <' . $email . '>' : $email;
819 + if ( '' !== $name ) {
820 + $email = $name . ' <' . $email . '>';
821 + }
822 +
823 + return $email;
813 824 }
814 825
815 826 /**
816 827 * Remove phone numbers from To addresses
@@ -820,37 +831,35 @@
820 831 *
821 832 * @return void
822 833 */
823 834 private function handle_phone_numbers() {
835 +
824 836 foreach ( $this->to as $key => $recipient ) {
825 - if ( '[admin_email]' === $recipient || is_email( $recipient ) ) {
826 - continue;
827 - }
837 + if ( '[admin_email]' !== $recipient && ! is_email( $recipient ) ) {
838 + $recipient = explode( ' ', $recipient );
828 839
829 - $recipient = explode( ' ', $recipient );
840 + if ( is_email( end( $recipient ) ) ) {
841 + continue;
842 + }
830 843
831 - if ( is_email( end( $recipient ) ) ) {
832 - continue;
833 - }
844 + do_action(
845 + 'frm_send_to_not_email',
846 + array(
847 + 'e' => $recipient,
848 + 'subject' => $this->subject,
849 + 'mail_body' => $this->message,
850 + 'reply_to' => $this->reply_to,
851 + 'from' => $this->from,
852 + 'plain_text' => $this->is_plain_text,
853 + 'attachments' => $this->attachments,
854 + 'form' => $this->form,
855 + 'email_key' => $key,
856 + )
857 + );
834 858
835 - do_action(
836 - 'frm_send_to_not_email',
837 - array(
838 - 'e' => $recipient,
839 - 'subject' => $this->subject,
840 - 'mail_body' => $this->message,
841 - 'reply_to' => $this->reply_to,
842 - 'from' => $this->from,
843 - 'plain_text' => $this->is_plain_text,
844 - 'attachments' => $this->attachments,
845 - 'form' => $this->form,
846 - 'email_key' => $key,
847 - )
848 - );
849 -
850 - // Remove phone number from to addresses
851 - unset( $this->to[ $key ] );
852 - // end if
859 + // Remove phone number from to addresses
860 + unset( $this->to[ $key ] );
861 + }//end if
853 862 }//end foreach
854 863 }
855 864
856 865 /**
@@ -870,12 +879,10 @@
870 879 'subject' => $this->subject,
871 880 'message' => $this->message,
872 881 'attachments' => $this->attachments,
873 882 'plain_text' => $this->is_plain_text,
874 - 'email_key' => $this->email_key,
875 883 'form' => $this->form,
876 884 'entry' => $this->entry,
877 - 'email_style' => $this->settings['email_style'],
878 885 );
879 886 }
880 887
881 888 /**
@@ -923,9 +930,9 @@
923 930 * @return string
924 931 */
925 932 private function encode_subject( $subject ) {
926 933 if ( apply_filters( 'frm_encode_subject', false, $subject ) ) {
927 - return '=?' . $this->charset . '?B?' . base64_encode( $subject ) . '?=';
934 + $subject = '=?' . $this->charset . '?B?' . base64_encode( $subject ) . '?=';
928 935 }
929 936
930 937 return $subject;
931 938 }