| @@ -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 ( empty( $this->to ) ) { | |
| 179 | + if ( ! $this->to ) { | |
| 180 | 180 | return; |
| 181 | 181 | } |
| 182 | 182 | |
| 183 | 183 | $this->handle_phone_numbers(); |
| @@ -510,9 +510,9 @@ | ||
| 510 | 510 | * |
| 511 | 511 | * @return bool |
| 512 | 512 | */ |
| 513 | 513 | private function has_recipients() { |
| 514 | - return ! ( empty( $this->to ) && empty( $this->cc ) && empty( $this->bcc ) ); | |
| 514 | + return $this->to || $this->cc || $this->bcc; | |
| 515 | 515 | } |
| 516 | 516 | |
| 517 | 517 | /** |
| 518 | 518 | * Send an email |
| @@ -585,13 +585,13 @@ | ||
| 585 | 585 | */ |
| 586 | 586 | private function package_header() { |
| 587 | 587 | $header = array(); |
| 588 | 588 | |
| 589 | - if ( ! empty( $this->cc ) ) { | |
| 589 | + if ( $this->cc ) { | |
| 590 | 590 | $header[] = 'CC: ' . implode( ',', $this->cc ); |
| 591 | 591 | } |
| 592 | 592 | |
| 593 | - if ( ! empty( $this->bcc ) ) { | |
| 593 | + if ( $this->bcc ) { | |
| 594 | 594 | $header[] = 'BCC: ' . implode( ',', $this->bcc ); |
| 595 | 595 | } |
| 596 | 596 | |
| 597 | 597 | $header[] = 'From: ' . $this->from; |
| @@ -657,12 +657,12 @@ | ||
| 657 | 657 | * @since 2.03.04 |
| 658 | 658 | * |
| 659 | 659 | * @param string $emails |
| 660 | 660 | * |
| 661 | - * @return array|string $emails | |
| 661 | + * @return array|string Emails. | |
| 662 | 662 | */ |
| 663 | 663 | private function explode_emails( $emails ) { |
| 664 | - $emails = ! empty( $emails ) ? preg_split( '/(,|;)/', $emails ) : ''; | |
| 664 | + $emails = $emails ? preg_split( '/(,|;)/', $emails ) : ''; | |
| 665 | 665 | return is_array( $emails ) ? array_map( 'trim', $emails ) : trim( $emails ); |
| 666 | 666 | } |
| 667 | 667 | |
| 668 | 668 | /** |
| @@ -687,17 +687,17 @@ | ||
| 687 | 687 | |
| 688 | 688 | $parts = explode( ' ', $val ); |
| 689 | 689 | $email = end( $parts ); |
| 690 | 690 | |
| 691 | - if ( is_email( $email ) ) { | |
| 692 | - // If user enters a name and email | |
| 693 | - $name = trim( str_replace( $email, '', $val ) ); | |
| 694 | - } else { | |
| 691 | + if ( ! is_email( $email ) ) { | |
| 695 | 692 | // If user enters a name without an email |
| 696 | 693 | unset( $recipients[ $key ] ); |
| 697 | 694 | continue; |
| 698 | 695 | } |
| 699 | 696 | |
| 697 | + // If user enters a name and email | |
| 698 | + $name = trim( str_replace( $email, '', $val ) ); | |
| 699 | + | |
| 700 | 700 | $recipients[ $key ] = $this->format_from_email( $name, $email ); |
| 701 | 701 | }//end foreach |
| 702 | 702 | |
| 703 | 703 | return $recipients; |
| @@ -720,9 +720,9 @@ | ||
| 720 | 720 | } else { |
| 721 | 721 | list( $from_name, $from_email ) = $this->get_name_and_email_for_sender( $from ); |
| 722 | 722 | } |
| 723 | 723 | |
| 724 | - // if sending the email from a yahoo address, change it to the WordPress default | |
| 724 | + // If sending the email from a yahoo address, change it to the WordPress default | |
| 725 | 725 | if ( str_contains( $from_email, '@yahoo.com' ) ) { |
| 726 | 726 | // Get the site domain and get rid of www. |
| 727 | 727 | $sitename = strtolower( FrmAppHelper::get_server_value( 'SERVER_NAME' ) ); |
| 728 | 728 | |
| @@ -808,13 +808,9 @@ | ||
| 808 | 808 | * |
| 809 | 809 | * @return string |
| 810 | 810 | */ |
| 811 | 811 | private function format_from_email( $name, $email ) { |
| 812 | - if ( '' !== $name ) { | |
| 813 | - $email = $name . ' <' . $email . '>'; | |
| 814 | - } | |
| 815 | - | |
| 816 | - return $email; | |
| 812 | + return '' !== $name ? $name . ' <' . $email . '>' : $email; | |
| 817 | 813 | } |
| 818 | 814 | |
| 819 | 815 | /** |
| 820 | 816 | * Remove phone numbers from To addresses |
| @@ -825,33 +821,36 @@ | ||
| 825 | 821 | * @return void |
| 826 | 822 | */ |
| 827 | 823 | private function handle_phone_numbers() { |
| 828 | 824 | foreach ( $this->to as $key => $recipient ) { |
| 829 | - if ( '[admin_email]' !== $recipient && ! is_email( $recipient ) ) { | |
| 830 | - $recipient = explode( ' ', $recipient ); | |
| 825 | + if ( '[admin_email]' === $recipient || is_email( $recipient ) ) { | |
| 826 | + continue; | |
| 827 | + } | |
| 831 | 828 | |
| 832 | - if ( is_email( end( $recipient ) ) ) { | |
| 833 | - continue; | |
| 834 | - } | |
| 829 | + $recipient = explode( ' ', $recipient ); | |
| 835 | 830 | |
| 836 | - do_action( | |
| 837 | - 'frm_send_to_not_email', | |
| 838 | - array( | |
| 839 | - 'e' => $recipient, | |
| 840 | - 'subject' => $this->subject, | |
| 841 | - 'mail_body' => $this->message, | |
| 842 | - 'reply_to' => $this->reply_to, | |
| 843 | - 'from' => $this->from, | |
| 844 | - 'plain_text' => $this->is_plain_text, | |
| 845 | - 'attachments' => $this->attachments, | |
| 846 | - 'form' => $this->form, | |
| 847 | - 'email_key' => $key, | |
| 848 | - ) | |
| 849 | - ); | |
| 831 | + if ( is_email( end( $recipient ) ) ) { | |
| 832 | + continue; | |
| 833 | + } | |
| 850 | 834 | |
| 851 | - // Remove phone number from to addresses | |
| 852 | - unset( $this->to[ $key ] ); | |
| 853 | - }//end if | |
| 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 | |
| 854 | 853 | }//end foreach |
| 855 | 854 | } |
| 856 | 855 | |
| 857 | 856 | /** |
| @@ -924,9 +923,9 @@ | ||
| 924 | 923 | * @return string |
| 925 | 924 | */ |
| 926 | 925 | private function encode_subject( $subject ) { |
| 927 | 926 | if ( apply_filters( 'frm_encode_subject', false, $subject ) ) { |
| 928 | - $subject = '=?' . $this->charset . '?B?' . base64_encode( $subject ) . '?='; | |
| 927 | + return '=?' . $this->charset . '?B?' . base64_encode( $subject ) . '?='; | |
| 929 | 928 | } |
| 930 | 929 | |
| 931 | 930 | return $subject; |
| 932 | 931 | } |