| @@ -7,99 +7,30 @@ | ||
| 7 | 7 | * @since 2.03.04 |
| 8 | 8 | */ |
| 9 | 9 | class FrmEmail { |
| 10 | 10 | |
| 11 | - /** | |
| 12 | - * @var string $email_key | |
| 13 | - */ | |
| 14 | 11 | private $email_key = ''; |
| 15 | - | |
| 16 | - /** | |
| 17 | - * @var array $to | |
| 18 | - */ | |
| 19 | 12 | private $to = array(); |
| 20 | - | |
| 21 | - /** | |
| 22 | - * @var array $cc | |
| 23 | - */ | |
| 24 | 13 | private $cc = array(); |
| 25 | - | |
| 26 | - /** | |
| 27 | - * @var array $bcc | |
| 28 | - */ | |
| 29 | 14 | private $bcc = array(); |
| 30 | - | |
| 31 | - /** | |
| 32 | - * @var string $from | |
| 33 | - */ | |
| 34 | 15 | private $from = ''; |
| 35 | - | |
| 36 | - /** | |
| 37 | - * @var string $reply_to | |
| 38 | - */ | |
| 39 | 16 | private $reply_to = ''; |
| 40 | - | |
| 41 | - /** | |
| 42 | - * @var string $subject | |
| 43 | - */ | |
| 44 | 17 | private $subject = ''; |
| 45 | - | |
| 46 | - /** | |
| 47 | - * @var string $message | |
| 48 | - */ | |
| 49 | 18 | private $message = ''; |
| 50 | - | |
| 51 | - /** | |
| 52 | - * @var array $attachments | |
| 53 | - */ | |
| 54 | 19 | private $attachments = array(); |
| 55 | 20 | |
| 56 | - /** | |
| 57 | - * @var bool $is_plain_text | |
| 58 | - */ | |
| 59 | 21 | private $is_plain_text = false; |
| 60 | - | |
| 61 | - /** | |
| 62 | - * @var bool $is_single_recipient | |
| 63 | - */ | |
| 64 | 22 | private $is_single_recipient = false; |
| 65 | - | |
| 66 | - /** | |
| 67 | - * @var bool $include_user_info | |
| 68 | - */ | |
| 69 | 23 | private $include_user_info = false; |
| 70 | 24 | |
| 71 | - /** | |
| 72 | - * @var string $charset | |
| 73 | - */ | |
| 74 | 25 | private $charset = ''; |
| 75 | - | |
| 76 | - /** | |
| 77 | - * @var string $content_type | |
| 78 | - */ | |
| 79 | 26 | private $content_type = 'text/html'; |
| 80 | 27 | |
| 81 | - /** | |
| 82 | - * @var array $settings | |
| 83 | - */ | |
| 84 | 28 | private $settings = array(); |
| 85 | - | |
| 86 | - /** | |
| 87 | - * @var stdClass $entry | |
| 88 | - */ | |
| 89 | 29 | private $entry; |
| 90 | - | |
| 91 | - /** | |
| 92 | - * @var stdClass $form | |
| 93 | - */ | |
| 94 | 30 | private $form; |
| 95 | 31 | |
| 96 | 32 | /** |
| 97 | - * @var int $action_id | |
| 98 | - */ | |
| 99 | - private $action_id = 0; | |
| 100 | - | |
| 101 | - /** | |
| 102 | 33 | * FrmEmail constructor |
| 103 | 34 | * |
| 104 | 35 | * @param object $action |
| 105 | 36 | * @param object $entry |
| @@ -106,12 +37,11 @@ | ||
| 106 | 37 | * @param object $form |
| 107 | 38 | */ |
| 108 | 39 | public function __construct( $action, $entry, $form ) { |
| 109 | 40 | $this->set_email_key( $action ); |
| 110 | - $this->entry = $entry; | |
| 111 | - $this->form = $form; | |
| 112 | - $this->settings = $action->post_content; | |
| 113 | - $this->action_id = (int) $action->ID; | |
| 41 | + $this->entry = $entry; | |
| 42 | + $this->form = $form; | |
| 43 | + $this->settings = $action->post_content; | |
| 114 | 44 | |
| 115 | 45 | $user_id_args = self::get_user_id_args( $form->id ); |
| 116 | 46 | $this->set_to( $user_id_args ); |
| 117 | 47 | $this->set_cc( $user_id_args ); |
| @@ -141,10 +71,8 @@ | ||
| 141 | 71 | * |
| 142 | 72 | * @since 2.03.04 |
| 143 | 73 | * |
| 144 | 74 | * @param object $action |
| 145 | - * | |
| 146 | - * @return void | |
| 147 | 75 | */ |
| 148 | 76 | private function set_email_key( $action ) { |
| 149 | 77 | $this->email_key = $action->ID; |
| 150 | 78 | } |
| @@ -154,10 +82,8 @@ | ||
| 154 | 82 | * |
| 155 | 83 | * @since 2.03.04 |
| 156 | 84 | * |
| 157 | 85 | * @param array $user_id_args |
| 158 | - * | |
| 159 | - * @return void | |
| 160 | 86 | */ |
| 161 | 87 | private function set_to( $user_id_args ) { |
| 162 | 88 | $to = $this->prepare_email_setting( $this->settings['email_to'], $user_id_args ); |
| 163 | 89 | $to = $this->explode_emails( $to ); |
| @@ -190,10 +116,8 @@ | ||
| 190 | 116 | * |
| 191 | 117 | * @since 2.03.04 |
| 192 | 118 | * |
| 193 | 119 | * @param array $user_id_args |
| 194 | - * | |
| 195 | - * @return void | |
| 196 | 120 | */ |
| 197 | 121 | private function set_cc( $user_id_args ) { |
| 198 | 122 | $this->cc = $this->prepare_additional_recipients( $this->settings['cc'], $user_id_args ); |
| 199 | 123 | } |
| @@ -203,10 +127,8 @@ | ||
| 203 | 127 | * |
| 204 | 128 | * @since 2.03.04 |
| 205 | 129 | * |
| 206 | 130 | * @param array $user_id_args |
| 207 | - * | |
| 208 | - * @return void | |
| 209 | 131 | */ |
| 210 | 132 | private function set_bcc( $user_id_args ) { |
| 211 | 133 | $this->bcc = $this->prepare_additional_recipients( $this->settings['bcc'], $user_id_args ); |
| 212 | 134 | } |
| @@ -236,9 +158,8 @@ | ||
| 236 | 158 | * |
| 237 | 159 | * @since 2.03.04 |
| 238 | 160 | * |
| 239 | 161 | * @param array $user_id_args |
| 240 | - * @return void | |
| 241 | 162 | */ |
| 242 | 163 | private function set_from( $user_id_args ) { |
| 243 | 164 | if ( empty( $this->settings['from'] ) ) { |
| 244 | 165 | $from = get_option( 'admin_email' ); |
| @@ -254,22 +175,17 @@ | ||
| 254 | 175 | * |
| 255 | 176 | * @since 2.03.04 |
| 256 | 177 | * |
| 257 | 178 | * @param array $user_id_args |
| 258 | - * | |
| 259 | - * @return void | |
| 260 | 179 | */ |
| 261 | 180 | private function set_reply_to( $user_id_args ) { |
| 262 | 181 | $this->reply_to = trim( $this->settings['reply_to'] ); |
| 263 | 182 | |
| 264 | - if ( $this->reply_to ) { | |
| 183 | + if ( empty( $this->reply_to ) ) { | |
| 184 | + $this->reply_to = $this->get_email_from_name( $this->from ); | |
| 185 | + } else { | |
| 265 | 186 | $this->reply_to = $this->prepare_email_setting( $this->settings['reply_to'], $user_id_args ); |
| 266 | 187 | } |
| 267 | - | |
| 268 | - if ( ! $this->reply_to ) { | |
| 269 | - $this->reply_to = $this->get_email_from_name( $this->from ); | |
| 270 | - } | |
| 271 | - | |
| 272 | 188 | $this->reply_to = $this->format_reply_to( $this->reply_to ); |
| 273 | 189 | } |
| 274 | 190 | |
| 275 | 191 | /** |
| @@ -276,10 +192,8 @@ | ||
| 276 | 192 | * Set the is_plain_text property |
| 277 | 193 | * This should be set before the message |
| 278 | 194 | * |
| 279 | 195 | * @since 2.03.04 |
| 280 | - * | |
| 281 | - * @return void | |
| 282 | 196 | */ |
| 283 | 197 | private function set_is_plain_text() { |
| 284 | 198 | if ( $this->settings['plain_text'] ) { |
| 285 | 199 | $this->is_plain_text = true; |
| @@ -290,10 +204,8 @@ | ||
| 290 | 204 | * Set the include_user_info property |
| 291 | 205 | * This should be set before the message |
| 292 | 206 | * |
| 293 | 207 | * @since 2.03.04 |
| 294 | - * | |
| 295 | - * @return void | |
| 296 | 208 | */ |
| 297 | 209 | private function set_include_user_info() { |
| 298 | 210 | if ( isset( $this->settings['inc_user_info'] ) ) { |
| 299 | 211 | $this->include_user_info = $this->settings['inc_user_info']; |
| @@ -305,11 +217,8 @@ | ||
| 305 | 217 | * |
| 306 | 218 | * @since 2.03.04 |
| 307 | 219 | * |
| 308 | 220 | * @param $action |
| 309 | - * @param object $action | |
| 310 | - * | |
| 311 | - * @return void | |
| 312 | 221 | */ |
| 313 | 222 | private function set_is_single_recipient( $action ) { |
| 314 | 223 | $args = array( |
| 315 | 224 | 'form' => $this->form, |
| @@ -328,10 +237,8 @@ | ||
| 328 | 237 | /** |
| 329 | 238 | * Set the charset |
| 330 | 239 | * |
| 331 | 240 | * @since 2.03.04 |
| 332 | - * | |
| 333 | - * @return void | |
| 334 | 241 | */ |
| 335 | 242 | private function set_charset() { |
| 336 | 243 | $this->charset = get_option( 'blog_charset' ); |
| 337 | 244 | } |
| @@ -339,10 +246,8 @@ | ||
| 339 | 246 | /** |
| 340 | 247 | * Set the content type |
| 341 | 248 | * |
| 342 | 249 | * @since 2.03.04 |
| 343 | - * | |
| 344 | - * @return void | |
| 345 | 250 | */ |
| 346 | 251 | private function set_content_type() { |
| 347 | 252 | if ( $this->is_plain_text ) { |
| 348 | 253 | $this->content_type = 'text/plain'; |
| @@ -352,10 +257,8 @@ | ||
| 352 | 257 | /** |
| 353 | 258 | * Set the subject |
| 354 | 259 | * |
| 355 | 260 | * @since 2.03.04 |
| 356 | - * | |
| 357 | - * @return void | |
| 358 | 261 | */ |
| 359 | 262 | private function set_subject() { |
| 360 | 263 | if ( empty( $this->settings['email_subject'] ) ) { |
| 361 | 264 | /* translators: %1$s: Form name, %2$s: Site name */ |
| @@ -363,9 +266,8 @@ | ||
| 363 | 266 | } else { |
| 364 | 267 | $this->subject = $this->settings['email_subject']; |
| 365 | 268 | } |
| 366 | 269 | |
| 367 | - // This also replaces [sitename] shortcode in default. | |
| 368 | 270 | $this->subject = FrmFieldsHelper::basic_replace_shortcodes( $this->subject, $this->form, $this->entry ); |
| 369 | 271 | |
| 370 | 272 | $args = array( |
| 371 | 273 | 'form' => $this->form, |
| @@ -372,8 +274,9 @@ | ||
| 372 | 274 | 'entry' => $this->entry, |
| 373 | 275 | 'email_key' => $this->email_key, |
| 374 | 276 | ); |
| 375 | 277 | $this->subject = apply_filters( 'frm_email_subject', $this->subject, $args ); |
| 278 | + | |
| 376 | 279 | $this->subject = wp_specialchars_decode( strip_tags( stripslashes( $this->subject ) ), ENT_QUOTES ); |
| 377 | 280 | } |
| 378 | 281 | |
| 379 | 282 | /** |
| @@ -379,20 +282,12 @@ | ||
| 379 | 282 | /** |
| 380 | 283 | * Set the email message |
| 381 | 284 | * |
| 382 | 285 | * @since 2.03.04 |
| 383 | - * | |
| 384 | - * @return void | |
| 385 | 286 | */ |
| 386 | 287 | private function set_message() { |
| 387 | - $this->message = $this->settings['email_message']; | |
| 288 | + $this->message = FrmFieldsHelper::basic_replace_shortcodes( $this->settings['email_message'], $this->form, $this->entry ); | |
| 388 | 289 | |
| 389 | - if ( ! $this->is_plain_text ) { | |
| 390 | - $this->message = html_entity_decode( $this->message ); // The decode is to support [default-html] shortcodes. | |
| 391 | - } | |
| 392 | - | |
| 393 | - $this->message = FrmFieldsHelper::basic_replace_shortcodes( $this->message, $this->form, $this->entry ); | |
| 394 | - | |
| 395 | 290 | $prev_mail_body = $this->message; |
| 396 | 291 | $pass_entry = clone $this->entry; // make a copy to prevent changes by reference |
| 397 | 292 | $mail_body = FrmEntriesHelper::replace_default_message( |
| 398 | 293 | $prev_mail_body, |
| @@ -418,35 +313,13 @@ | ||
| 418 | 313 | $this->message = do_shortcode( $this->message ); |
| 419 | 314 | |
| 420 | 315 | if ( $this->is_plain_text ) { |
| 421 | 316 | $this->message = wp_specialchars_decode( strip_tags( $this->message ), ENT_QUOTES ); |
| 422 | - } else { | |
| 423 | - $this->add_autop(); | |
| 424 | 317 | } |
| 425 | 318 | |
| 426 | 319 | $this->message = apply_filters( 'frm_email_message', $this->message, $this->package_atts() ); |
| 427 | 320 | } |
| 428 | 321 | |
| 429 | - /** | |
| 430 | - * Runs message through autop, extracting the content inside body tag if it has <body>. | |
| 431 | - * | |
| 432 | - * @return void | |
| 433 | - */ | |
| 434 | - private function add_autop() { | |
| 435 | - $message = $this->message; | |
| 436 | - $result = preg_match( '/<body[^>]*>([\s\S]*?)<\/body>/', $message, $match ); | |
| 437 | - if ( ! empty( $match[1] ) ) { | |
| 438 | - $this->message = str_replace( $match[1], trim( wpautop( $match[1] ) ), $message ); | |
| 439 | - } else { | |
| 440 | - $this->message = trim( wpautop( $message ) ); | |
| 441 | - } | |
| 442 | - } | |
| 443 | - | |
| 444 | - /** | |
| 445 | - * @param string $mail_body | |
| 446 | - * | |
| 447 | - * @return void | |
| 448 | - */ | |
| 449 | 322 | private function maybe_add_ip( &$mail_body ) { |
| 450 | 323 | if ( ! empty( $this->entry->ip ) ) { |
| 451 | 324 | $mail_body .= __( 'IP Address', 'formidable' ) . ': ' . $this->entry->ip . "\r\n"; |
| 452 | 325 | } |
| @@ -455,11 +328,8 @@ | ||
| 455 | 328 | /** |
| 456 | 329 | * Set the attachments for an email message |
| 457 | 330 | * |
| 458 | 331 | * @since 2.03.04 |
| 459 | - * @since 5.0.16 added new action_id key to $args. | |
| 460 | - * | |
| 461 | - * @return void | |
| 462 | 332 | */ |
| 463 | 333 | private function set_attachments() { |
| 464 | 334 | $args = array( |
| 465 | 335 | 'entry' => $this->entry, |
| @@ -464,9 +334,8 @@ | ||
| 464 | 334 | $args = array( |
| 465 | 335 | 'entry' => $this->entry, |
| 466 | 336 | 'email_key' => $this->email_key, |
| 467 | 337 | 'settings' => $this->settings, |
| 468 | - 'action_id' => $this->action_id, | |
| 469 | 338 | ); |
| 470 | 339 | |
| 471 | 340 | $this->attachments = apply_filters( 'frm_notification_attachment', array(), $this->form, $args ); |
| 472 | 341 | } |
| @@ -565,11 +434,9 @@ | ||
| 565 | 434 | |
| 566 | 435 | $sent = wp_mail( $recipient, $subject, $this->message, $header, $this->attachments ); |
| 567 | 436 | |
| 568 | 437 | if ( ! $sent ) { |
| 569 | - if ( is_array( $header ) ) { | |
| 570 | - $header = implode( "\r\n", $header ); | |
| 571 | - } | |
| 438 | + $header = 'From: ' . $this->from . "\r\n"; | |
| 572 | 439 | $recipient = implode( ',', (array) $recipient ); |
| 573 | 440 | $sent = mail( $recipient, $subject, $this->message, $header ); |
| 574 | 441 | } |
| 575 | 442 | |
| @@ -767,12 +634,8 @@ | ||
| 767 | 634 | /** |
| 768 | 635 | * Get only the email if the name and email have been combined |
| 769 | 636 | * |
| 770 | 637 | * @since 3.0.06 |
| 771 | - * | |
| 772 | - * @param string $name | |
| 773 | - * | |
| 774 | - * @return string | |
| 775 | 638 | */ |
| 776 | 639 | private function get_email_from_name( $name ) { |
| 777 | 640 | $email = trim( trim( $name, '>' ), '<' ); |
| 778 | 641 | if ( strpos( $email, '<' ) !== false ) { |
| @@ -808,11 +671,8 @@ | ||
| 808 | 671 | } |
| 809 | 672 | |
| 810 | 673 | /** |
| 811 | 674 | * @since 3.0.06 |
| 812 | - * | |
| 813 | - * @param string $name | |
| 814 | - * @param string $email | |
| 815 | 675 | */ |
| 816 | 676 | private function format_from_email( $name, $email ) { |
| 817 | 677 | if ( '' !== $name ) { |
| 818 | 678 | $email = $name . ' <' . $email . '>'; |
| @@ -825,10 +685,8 @@ | ||
| 825 | 685 | * Remove phone numbers from To addresses |
| 826 | 686 | * Send the phone numbers to the frm_send_to_not_email hook |
| 827 | 687 | * |
| 828 | 688 | * @since 2.03.04 |
| 829 | - * | |
| 830 | - * @return void | |
| 831 | 689 | */ |
| 832 | 690 | private function handle_phone_numbers() { |
| 833 | 691 | |
| 834 | 692 | foreach ( $this->to as $key => $recipient ) { |
| @@ -886,10 +744,8 @@ | ||
| 886 | 744 | /** |
| 887 | 745 | * Remove the Buddypress email filters |
| 888 | 746 | * |
| 889 | 747 | * @since 2.03.04 |
| 890 | - * | |
| 891 | - * @return void | |
| 892 | 748 | */ |
| 893 | 749 | private function remove_buddypress_filters() { |
| 894 | 750 | remove_filter( 'wp_mail_from', 'bp_core_email_from_address_filter' ); |
| 895 | 751 | remove_filter( 'wp_mail_from_name', 'bp_core_email_from_name_filter' ); |
| @@ -899,10 +755,8 @@ | ||
| 899 | 755 | * Add Mandrill line break filter |
| 900 | 756 | * Remove line breaks in HTML emails to prevent conflicts with Mandrill |
| 901 | 757 | * |
| 902 | 758 | * @since 2.03.04 |
| 903 | - * | |
| 904 | - * @return void | |
| 905 | 759 | */ |
| 906 | 760 | private function add_mandrill_filter() { |
| 907 | 761 | if ( ! $this->is_plain_text ) { |
| 908 | 762 | add_filter( 'mandrill_nl2br', 'FrmEmailHelper::remove_mandrill_br' ); |
| @@ -912,10 +766,8 @@ | ||
| 912 | 766 | /** |
| 913 | 767 | * Remove Mandrill line break filter |
| 914 | 768 | * |
| 915 | 769 | * @since 2.03.04 |
| 916 | - * | |
| 917 | - * @return void | |
| 918 | 770 | */ |
| 919 | 771 | private function remove_mandrill_filter() { |
| 920 | 772 | remove_filter( 'mandrill_nl2br', 'FrmEmailHelper::remove_mandrill_br' ); |
| 921 | 773 | } |