PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.11
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.11
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 +92 -87 6.326.11 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,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
@@ -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,11 +415,12 @@
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 - $this->message = str_replace( ' ', '', $this->message );
426 423 } else {
427 424 $this->add_autop();
428 425 }
429 426
@@ -436,10 +433,9 @@
436 433 * @return void
437 434 */
438 435 private function add_autop() {
439 436 $message = $this->message;
440 - preg_match( '/<body[^>]*>([\s\S]*?)<\/body>/', $message, $match );
441 -
437 + $result = preg_match( '/<body[^>]*>([\s\S]*?)<\/body>/', $message, $match );
442 438 if ( ! empty( $match[1] ) ) {
443 439 $this->message = str_replace( $match[1], trim( wpautop( $match[1] ) ), $message );
444 440 } else {
445 441 $this->message = trim( wpautop( $message ) );
@@ -484,24 +480,28 @@
484 480 * @return bool|mixed|void
485 481 */
486 482 public function should_send() {
487 483 if ( ! $this->has_recipients() ) {
488 - return false;
484 + $send = false;
485 + } else {
486 +
487 + $filter_args = array(
488 + 'message' => $this->message,
489 + 'subject' => $this->subject,
490 + 'recipient' => $this->to,
491 + 'header' => $this->package_header(),
492 + );
493 +
494 + /**
495 + * Stop an email based on the message, subject, recipient,
496 + * or any information included in the email header
497 + *
498 + * @since 2.2.8
499 + */
500 + $send = apply_filters( 'frm_send_email', true, $filter_args );
489 501 }
490 502
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 );
503 + return $send;
504 504 }
505 505
506 506 /**
507 507 * Check if an email has any recipients
@@ -510,9 +510,12 @@
510 510 *
511 511 * @return bool
512 512 */
513 513 private function has_recipients() {
514 - return $this->to || $this->cc || $this->bcc;
514 + if ( empty( $this->to ) && empty( $this->cc ) && empty( $this->bcc ) ) {
515 + return false;
516 + }
517 + return true;
515 518 }
516 519
517 520 /**
518 521 * Send an email
@@ -525,9 +528,8 @@
525 528 $this->remove_buddypress_filters();
526 529 $this->add_mandrill_filter();
527 530
528 531 $sent = false;
529 -
530 532 if ( count( $this->to ) > 1 && $this->is_single_recipient ) {
531 533 foreach ( $this->to as $recipient ) {
532 534 $sent = $this->send_single( $recipient );
533 535 }
@@ -559,15 +561,15 @@
559 561 )
560 562 );
561 563
562 564 $subject = $this->encode_subject( $this->subject );
563 - $sent = wp_mail( $recipient, $subject, $this->message, $header, $this->attachments );
564 565
566 + $sent = wp_mail( $recipient, $subject, $this->message, $header, $this->attachments );
567 +
565 568 if ( ! $sent ) {
566 569 if ( is_array( $header ) ) {
567 570 $header = implode( "\r\n", $header );
568 571 }
569 -
570 572 $recipient = implode( ',', (array) $recipient );
571 573 $sent = mail( $recipient, $subject, $this->message, $header );
572 574 }
573 575
@@ -585,13 +587,13 @@
585 587 */
586 588 private function package_header() {
587 589 $header = array();
588 590
589 - if ( $this->cc ) {
591 + if ( ! empty( $this->cc ) ) {
590 592 $header[] = 'CC: ' . implode( ',', $this->cc );
591 593 }
592 594
593 - if ( $this->bcc ) {
595 + if ( ! empty( $this->bcc ) ) {
594 596 $header[] = 'BCC: ' . implode( ',', $this->bcc );
595 597 }
596 598
597 599 $header[] = 'From: ' . $this->from;
@@ -616,9 +618,8 @@
616 618 'field_key' => '',
617 619 );
618 620
619 621 $user_id_args['field_id'] = FrmEmailHelper::get_user_id_field_for_form( $form_id );
620 -
621 622 if ( $user_id_args['field_id'] ) {
622 623 $user_id_args['field_key'] = FrmField::get_key_by_id( $user_id_args['field_id'] );
623 624 }
624 625
@@ -635,11 +636,11 @@
635 636 *
636 637 * @return string
637 638 */
638 639 private function prepare_email_setting( $value, $user_id_args ) {
639 - if ( str_contains( $value, '[' . $user_id_args['field_id'] . ']' ) ) {
640 + if ( strpos( $value, '[' . $user_id_args['field_id'] . ']' ) !== false ) {
640 641 $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'] . ']' ) ) {
642 + } elseif ( strpos( $value, '[' . $user_id_args['field_key'] . ']' ) !== false ) {
642 643 $value = str_replace( '[' . $user_id_args['field_key'] . ']', '[' . $user_id_args['field_key'] . ' show="user_email"]', $value );
643 644 }
644 645
645 646 $value = FrmFieldsHelper::basic_replace_shortcodes( $value, $this->form, $this->entry );
@@ -645,10 +646,11 @@
645 646 $value = FrmFieldsHelper::basic_replace_shortcodes( $value, $this->form, $this->entry );
646 647
647 648 // Remove brackets and add a space in case there isn't one
648 649 $value = str_replace( '<', ' ', $value );
650 + $value = str_replace( array( '"', '>' ), '', $value );
649 651
650 - return str_replace( array( '"', '>' ), '', $value );
652 + return $value;
651 653 }
652 654
653 655 /**
654 656 * Extract the emails from cc and bcc. Allow separation by , or ;.
@@ -657,13 +659,19 @@
657 659 * @since 2.03.04
658 660 *
659 661 * @param string $emails
660 662 *
661 - * @return array|string Emails.
663 + * @return array|string $emails
662 664 */
663 665 private function explode_emails( $emails ) {
664 - $emails = $emails ? preg_split( '/(,|;)/', $emails ) : '';
665 - return is_array( $emails ) ? array_map( 'trim', $emails ) : trim( $emails );
666 + $emails = ( ! empty( $emails ) ? preg_split( '/(,|;)/', $emails ) : '' );
667 + if ( is_array( $emails ) ) {
668 + $emails = array_map( 'trim', $emails );
669 + } else {
670 + $emails = trim( $emails );
671 + }
672 +
673 + return $emails;
666 674 }
667 675
668 676 /**
669 677 * Format the recipients( to, cc, bcc)
@@ -672,9 +680,9 @@
672 680 *
673 681 * @return array
674 682 */
675 683 private function format_recipients( $recipients ) {
676 - if ( ! $recipients ) {
684 + if ( empty( $recipients ) ) {
677 685 return $recipients;
678 686 }
679 687
680 688 foreach ( $recipients as $key => $val ) {
@@ -687,17 +695,17 @@
687 695
688 696 $parts = explode( ' ', $val );
689 697 $email = end( $parts );
690 698
691 - if ( ! is_email( $email ) ) {
699 + if ( is_email( $email ) ) {
700 + // If user enters a name and email
701 + $name = trim( str_replace( $email, '', $val ) );
702 + } else {
692 703 // If user enters a name without an email
693 704 unset( $recipients[ $key ] );
694 705 continue;
695 706 }
696 707
697 - // If user enters a name and email
698 - $name = trim( str_replace( $email, '', $val ) );
699 -
700 708 $recipients[ $key ] = $this->format_from_email( $name, $email );
701 709 }//end foreach
702 710
703 711 return $recipients;
@@ -720,14 +728,14 @@
720 728 } else {
721 729 list( $from_name, $from_email ) = $this->get_name_and_email_for_sender( $from );
722 730 }
723 731
724 - // If sending the email from a yahoo address, change it to the WordPress default
725 - if ( str_contains( $from_email, '@yahoo.com' ) ) {
732 + // if sending the email from a yahoo address, change it to the WordPress default
733 + if ( strpos( $from_email, '@yahoo.com' ) ) {
734 +
726 735 // Get the site domain and get rid of www.
727 736 $sitename = strtolower( FrmAppHelper::get_server_value( 'SERVER_NAME' ) );
728 -
729 - if ( str_starts_with( $sitename, 'www.' ) ) {
737 + if ( substr( $sitename, 0, 4 ) === 'www.' ) {
730 738 $sitename = substr( $sitename, 4 );
731 739 }
732 740
733 741 $from_email = 'wordpress@' . $sitename;
@@ -766,10 +774,9 @@
766 774 * @return string
767 775 */
768 776 private function get_email_from_name( $name ) {
769 777 $email = trim( trim( $name, '>' ), '<' );
770 -
771 - if ( str_contains( $email, '<' ) ) {
778 + if ( strpos( $email, '<' ) !== false ) {
772 779 $parts = explode( '<', $email );
773 780 $email = trim( $parts[1], '>' );
774 781 }
775 782
@@ -804,13 +811,15 @@
804 811 * @since 3.0.06
805 812 *
806 813 * @param string $name
807 814 * @param string $email
808 - *
809 - * @return string
810 815 */
811 816 private function format_from_email( $name, $email ) {
812 - return '' !== $name ? $name . ' <' . $email . '>' : $email;
817 + if ( '' !== $name ) {
818 + $email = $name . ' <' . $email . '>';
819 + }
820 +
821 + return $email;
813 822 }
814 823
815 824 /**
816 825 * Remove phone numbers from To addresses
@@ -820,37 +829,35 @@
820 829 *
821 830 * @return void
822 831 */
823 832 private function handle_phone_numbers() {
833 +
824 834 foreach ( $this->to as $key => $recipient ) {
825 - if ( '[admin_email]' === $recipient || is_email( $recipient ) ) {
826 - continue;
827 - }
835 + if ( '[admin_email]' !== $recipient && ! is_email( $recipient ) ) {
836 + $recipient = explode( ' ', $recipient );
828 837
829 - $recipient = explode( ' ', $recipient );
838 + if ( is_email( end( $recipient ) ) ) {
839 + continue;
840 + }
830 841
831 - if ( is_email( end( $recipient ) ) ) {
832 - continue;
833 - }
842 + do_action(
843 + 'frm_send_to_not_email',
844 + array(
845 + 'e' => $recipient,
846 + 'subject' => $this->subject,
847 + 'mail_body' => $this->message,
848 + 'reply_to' => $this->reply_to,
849 + 'from' => $this->from,
850 + 'plain_text' => $this->is_plain_text,
851 + 'attachments' => $this->attachments,
852 + 'form' => $this->form,
853 + 'email_key' => $key,
854 + )
855 + );
834 856
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
857 + // Remove phone number from to addresses
858 + unset( $this->to[ $key ] );
859 + }//end if
853 860 }//end foreach
854 861 }
855 862
856 863 /**
@@ -870,12 +877,10 @@
870 877 'subject' => $this->subject,
871 878 'message' => $this->message,
872 879 'attachments' => $this->attachments,
873 880 'plain_text' => $this->is_plain_text,
874 - 'email_key' => $this->email_key,
875 881 'form' => $this->form,
876 882 'entry' => $this->entry,
877 - 'email_style' => $this->settings['email_style'],
878 883 );
879 884 }
880 885
881 886 /**
@@ -923,9 +928,9 @@
923 928 * @return string
924 929 */
925 930 private function encode_subject( $subject ) {
926 931 if ( apply_filters( 'frm_encode_subject', false, $subject ) ) {
927 - return '=?' . $this->charset . '?B?' . base64_encode( $subject ) . '?=';
932 + $subject = '=?' . $this->charset . '?B?' . base64_encode( $subject ) . '?=';
928 933 }
929 934
930 935 return $subject;
931 936 }