PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.18
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.18
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 +91 -85 6.316.18 View file →
@@ -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,9 +236,8 @@
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'] ) ) {
@@ -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
@@ -400,13 +397,12 @@
400 397 $pass_entry = clone $this->entry;
401 398 $mail_body = FrmEntriesHelper::replace_default_message(
402 399 $prev_mail_body,
403 400 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'],
401 + 'id' => $this->entry->id,
402 + 'entry' => $pass_entry,
403 + 'plain_text' => $this->is_plain_text,
404 + 'user_info' => $this->include_user_info,
409 405 )
410 406 );
411 407
412 408 // Add the user info if it isn't already included
@@ -419,8 +415,10 @@
419 415 }
420 416
421 417 $this->message = $mail_body;
422 418
419 + $this->message = do_shortcode( $this->message );
420 +
423 421 if ( $this->is_plain_text ) {
424 422 $this->message = wp_specialchars_decode( strip_tags( $this->message ), ENT_QUOTES );
425 423 $this->message = str_replace( ' ', '', $this->message );
426 424 } else {
@@ -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,12 @@
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 + }
518 + return true;
515 519 }
516 520
517 521 /**
518 522 * Send an email
@@ -525,9 +529,8 @@
525 529 $this->remove_buddypress_filters();
526 530 $this->add_mandrill_filter();
527 531
528 532 $sent = false;
529 -
530 533 if ( count( $this->to ) > 1 && $this->is_single_recipient ) {
531 534 foreach ( $this->to as $recipient ) {
532 535 $sent = $this->send_single( $recipient );
533 536 }
@@ -559,15 +562,15 @@
559 562 )
560 563 );
561 564
562 565 $subject = $this->encode_subject( $this->subject );
563 - $sent = wp_mail( $recipient, $subject, $this->message, $header, $this->attachments );
564 566
567 + $sent = wp_mail( $recipient, $subject, $this->message, $header, $this->attachments );
568 +
565 569 if ( ! $sent ) {
566 570 if ( is_array( $header ) ) {
567 571 $header = implode( "\r\n", $header );
568 572 }
569 -
570 573 $recipient = implode( ',', (array) $recipient );
571 574 $sent = mail( $recipient, $subject, $this->message, $header );
572 575 }
573 576
@@ -585,13 +588,13 @@
585 588 */
586 589 private function package_header() {
587 590 $header = array();
588 591
589 - if ( $this->cc ) {
592 + if ( ! empty( $this->cc ) ) {
590 593 $header[] = 'CC: ' . implode( ',', $this->cc );
591 594 }
592 595
593 - if ( $this->bcc ) {
596 + if ( ! empty( $this->bcc ) ) {
594 597 $header[] = 'BCC: ' . implode( ',', $this->bcc );
595 598 }
596 599
597 600 $header[] = 'From: ' . $this->from;
@@ -616,9 +619,8 @@
616 619 'field_key' => '',
617 620 );
618 621
619 622 $user_id_args['field_id'] = FrmEmailHelper::get_user_id_field_for_form( $form_id );
620 -
621 623 if ( $user_id_args['field_id'] ) {
622 624 $user_id_args['field_key'] = FrmField::get_key_by_id( $user_id_args['field_id'] );
623 625 }
624 626
@@ -635,11 +637,11 @@
635 637 *
636 638 * @return string
637 639 */
638 640 private function prepare_email_setting( $value, $user_id_args ) {
639 - if ( str_contains( $value, '[' . $user_id_args['field_id'] . ']' ) ) {
641 + if ( strpos( $value, '[' . $user_id_args['field_id'] . ']' ) !== false ) {
640 642 $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'] . ']' ) ) {
643 + } elseif ( strpos( $value, '[' . $user_id_args['field_key'] . ']' ) !== false ) {
642 644 $value = str_replace( '[' . $user_id_args['field_key'] . ']', '[' . $user_id_args['field_key'] . ' show="user_email"]', $value );
643 645 }
644 646
645 647 $value = FrmFieldsHelper::basic_replace_shortcodes( $value, $this->form, $this->entry );
@@ -645,10 +647,11 @@
645 647 $value = FrmFieldsHelper::basic_replace_shortcodes( $value, $this->form, $this->entry );
646 648
647 649 // Remove brackets and add a space in case there isn't one
648 650 $value = str_replace( '<', ' ', $value );
651 + $value = str_replace( array( '"', '>' ), '', $value );
649 652
650 - return str_replace( array( '"', '>' ), '', $value );
653 + return $value;
651 654 }
652 655
653 656 /**
654 657 * Extract the emails from cc and bcc. Allow separation by , or ;.
@@ -657,13 +660,19 @@
657 660 * @since 2.03.04
658 661 *
659 662 * @param string $emails
660 663 *
661 - * @return array|string Emails.
664 + * @return array|string $emails
662 665 */
663 666 private function explode_emails( $emails ) {
664 - $emails = $emails ? preg_split( '/(,|;)/', $emails ) : '';
665 - return is_array( $emails ) ? array_map( 'trim', $emails ) : trim( $emails );
667 + $emails = ( ! empty( $emails ) ? preg_split( '/(,|;)/', $emails ) : '' );
668 + if ( is_array( $emails ) ) {
669 + $emails = array_map( 'trim', $emails );
670 + } else {
671 + $emails = trim( $emails );
672 + }
673 +
674 + return $emails;
666 675 }
667 676
668 677 /**
669 678 * Format the recipients( to, cc, bcc)
@@ -672,9 +681,9 @@
672 681 *
673 682 * @return array
674 683 */
675 684 private function format_recipients( $recipients ) {
676 - if ( ! $recipients ) {
685 + if ( empty( $recipients ) ) {
677 686 return $recipients;
678 687 }
679 688
680 689 foreach ( $recipients as $key => $val ) {
@@ -687,17 +696,17 @@
687 696
688 697 $parts = explode( ' ', $val );
689 698 $email = end( $parts );
690 699
691 - if ( ! is_email( $email ) ) {
700 + if ( is_email( $email ) ) {
701 + // If user enters a name and email
702 + $name = trim( str_replace( $email, '', $val ) );
703 + } else {
692 704 // If user enters a name without an email
693 705 unset( $recipients[ $key ] );
694 706 continue;
695 707 }
696 708
697 - // If user enters a name and email
698 - $name = trim( str_replace( $email, '', $val ) );
699 -
700 709 $recipients[ $key ] = $this->format_from_email( $name, $email );
701 710 }//end foreach
702 711
703 712 return $recipients;
@@ -720,14 +729,14 @@
720 729 } else {
721 730 list( $from_name, $from_email ) = $this->get_name_and_email_for_sender( $from );
722 731 }
723 732
724 - // If sending the email from a yahoo address, change it to the WordPress default
725 - if ( str_contains( $from_email, '@yahoo.com' ) ) {
733 + // if sending the email from a yahoo address, change it to the WordPress default
734 + if ( strpos( $from_email, '@yahoo.com' ) ) {
735 +
726 736 // Get the site domain and get rid of www.
727 737 $sitename = strtolower( FrmAppHelper::get_server_value( 'SERVER_NAME' ) );
728 -
729 - if ( str_starts_with( $sitename, 'www.' ) ) {
738 + if ( substr( $sitename, 0, 4 ) === 'www.' ) {
730 739 $sitename = substr( $sitename, 4 );
731 740 }
732 741
733 742 $from_email = 'wordpress@' . $sitename;
@@ -766,10 +775,9 @@
766 775 * @return string
767 776 */
768 777 private function get_email_from_name( $name ) {
769 778 $email = trim( trim( $name, '>' ), '<' );
770 -
771 - if ( str_contains( $email, '<' ) ) {
779 + if ( strpos( $email, '<' ) !== false ) {
772 780 $parts = explode( '<', $email );
773 781 $email = trim( $parts[1], '>' );
774 782 }
775 783
@@ -804,13 +812,15 @@
804 812 * @since 3.0.06
805 813 *
806 814 * @param string $name
807 815 * @param string $email
808 - *
809 - * @return string
810 816 */
811 817 private function format_from_email( $name, $email ) {
812 - return '' !== $name ? $name . ' <' . $email . '>' : $email;
818 + if ( '' !== $name ) {
819 + $email = $name . ' <' . $email . '>';
820 + }
821 +
822 + return $email;
813 823 }
814 824
815 825 /**
816 826 * Remove phone numbers from To addresses
@@ -820,37 +830,35 @@
820 830 *
821 831 * @return void
822 832 */
823 833 private function handle_phone_numbers() {
834 +
824 835 foreach ( $this->to as $key => $recipient ) {
825 - if ( '[admin_email]' === $recipient || is_email( $recipient ) ) {
826 - continue;
827 - }
836 + if ( '[admin_email]' !== $recipient && ! is_email( $recipient ) ) {
837 + $recipient = explode( ' ', $recipient );
828 838
829 - $recipient = explode( ' ', $recipient );
839 + if ( is_email( end( $recipient ) ) ) {
840 + continue;
841 + }
830 842
831 - if ( is_email( end( $recipient ) ) ) {
832 - continue;
833 - }
843 + do_action(
844 + 'frm_send_to_not_email',
845 + array(
846 + 'e' => $recipient,
847 + 'subject' => $this->subject,
848 + 'mail_body' => $this->message,
849 + 'reply_to' => $this->reply_to,
850 + 'from' => $this->from,
851 + 'plain_text' => $this->is_plain_text,
852 + 'attachments' => $this->attachments,
853 + 'form' => $this->form,
854 + 'email_key' => $key,
855 + )
856 + );
834 857
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
858 + // Remove phone number from to addresses
859 + unset( $this->to[ $key ] );
860 + }//end if
853 861 }//end foreach
854 862 }
855 863
856 864 /**
@@ -870,12 +878,10 @@
870 878 'subject' => $this->subject,
871 879 'message' => $this->message,
872 880 'attachments' => $this->attachments,
873 881 'plain_text' => $this->is_plain_text,
874 - 'email_key' => $this->email_key,
875 882 'form' => $this->form,
876 883 'entry' => $this->entry,
877 - 'email_style' => $this->settings['email_style'],
878 884 );
879 885 }
880 886
881 887 /**
@@ -923,9 +929,9 @@
923 929 * @return string
924 930 */
925 931 private function encode_subject( $subject ) {
926 932 if ( apply_filters( 'frm_encode_subject', false, $subject ) ) {
927 - return '=?' . $this->charset . '?B?' . base64_encode( $subject ) . '?=';
933 + $subject = '=?' . $this->charset . '?B?' . base64_encode( $subject ) . '?=';
928 934 }
929 935
930 936 return $subject;
931 937 }