PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 4.08
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v4.08
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 +118 -261 6.304.08 View file →
@@ -7,99 +7,30 @@
7 7 * @since 2.03.04
8 8 */
9 9 class FrmEmail {
10 10
11 - /**
12 - * @var string
13 - */
14 11 private $email_key = '';
15 -
16 - /**
17 - * @var array
18 - */
19 12 private $to = array();
20 -
21 - /**
22 - * @var array
23 - */
24 13 private $cc = array();
25 -
26 - /**
27 - * @var array
28 - */
29 14 private $bcc = array();
30 -
31 - /**
32 - * @var string
33 - */
34 15 private $from = '';
35 -
36 - /**
37 - * @var string
38 - */
39 16 private $reply_to = '';
40 -
41 - /**
42 - * @var string
43 - */
44 17 private $subject = '';
45 -
46 - /**
47 - * @var string
48 - */
49 18 private $message = '';
50 -
51 - /**
52 - * @var array
53 - */
54 19 private $attachments = array();
55 20
56 - /**
57 - * @var bool
58 - */
59 21 private $is_plain_text = false;
60 -
61 - /**
62 - * @var bool
63 - */
64 22 private $is_single_recipient = false;
65 -
66 - /**
67 - * @var bool
68 - */
69 23 private $include_user_info = false;
70 24
71 - /**
72 - * @var string
73 - */
74 25 private $charset = '';
75 -
76 - /**
77 - * @var string
78 - */
79 26 private $content_type = 'text/html';
80 27
81 - /**
82 - * @var array
83 - */
84 28 private $settings = array();
85 -
86 - /**
87 - * @var stdClass
88 - */
89 29 private $entry;
90 -
91 - /**
92 - * @var stdClass
93 - */
94 30 private $form;
95 31
96 32 /**
97 - * @var int
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 );
@@ -175,9 +101,9 @@
175 101 $to = apply_filters( 'frm_to_email', $to, $values, $this->form->id, $args );
176 102
177 103 $this->to = array_unique( (array) $to );
178 104
179 - if ( ! $this->to ) {
105 + if ( empty( $this->to ) ) {
180 106 return;
181 107 }
182 108
183 109 $this->handle_phone_numbers();
@@ -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 }
@@ -216,9 +138,9 @@
216 138 *
217 139 * @since 2.03.04
218 140 *
219 141 * @param string $recipients
220 - * @param array $user_id_args
142 + * @param array $user_id_args
221 143 *
222 144 * @return array
223 145 */
224 146 private function prepare_additional_recipients( $recipients, $user_id_args ) {
@@ -223,11 +145,13 @@
223 145 */
224 146 private function prepare_additional_recipients( $recipients, $user_id_args ) {
225 147 $recipients = $this->prepare_email_setting( $recipients, $user_id_args );
226 148 $recipients = $this->explode_emails( $recipients );
149 +
227 150 $recipients = array_unique( (array) $recipients );
151 + $recipients = $this->format_recipients( $recipients );
228 152
229 - return $this->format_recipients( $recipients );
153 + return $recipients;
230 154 }
231 155
232 156 /**
233 157 * Set the From addresses
@@ -234,14 +158,12 @@
234 158 *
235 159 * @since 2.03.04
236 160 *
237 161 * @param array $user_id_args
238 - *
239 - * @return void
240 162 */
241 163 private function set_from( $user_id_args ) {
242 164 if ( empty( $this->settings['from'] ) ) {
243 - $from = FrmEmailHelper::get_default_from_email();
165 + $from = get_option( 'admin_email' );
244 166 } else {
245 167 $from = $this->prepare_email_setting( $this->settings['from'], $user_id_args );
246 168 }
247 169
@@ -253,22 +175,17 @@
253 175 *
254 176 * @since 2.03.04
255 177 *
256 178 * @param array $user_id_args
257 - *
258 - * @return void
259 179 */
260 180 private function set_reply_to( $user_id_args ) {
261 181 $this->reply_to = trim( $this->settings['reply_to'] );
262 182
263 - if ( $this->reply_to ) {
183 + if ( empty( $this->reply_to ) ) {
184 + $this->reply_to = $this->get_email_from_name( $this->from );
185 + } else {
264 186 $this->reply_to = $this->prepare_email_setting( $this->settings['reply_to'], $user_id_args );
265 187 }
266 -
267 - if ( ! $this->reply_to ) {
268 - $this->reply_to = $this->get_email_from_name( $this->from );
269 - }
270 -
271 188 $this->reply_to = $this->format_reply_to( $this->reply_to );
272 189 }
273 190
274 191 /**
@@ -275,19 +192,13 @@
275 192 * Set the is_plain_text property
276 193 * This should be set before the message
277 194 *
278 195 * @since 2.03.04
279 - *
280 - * @return void
281 196 */
282 197 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;
198 + if ( $this->settings['plain_text'] ) {
199 + $this->is_plain_text = true;
287 200 }
288 -
289 - $this->is_plain_text = 'plain' === $this->settings['email_style'];
290 201 }
291 202
292 203 /**
293 204 * Set the include_user_info property
@@ -293,10 +204,8 @@
293 204 * Set the include_user_info property
294 205 * This should be set before the message
295 206 *
296 207 * @since 2.03.04
297 - *
298 - * @return void
299 208 */
300 209 private function set_include_user_info() {
301 210 if ( isset( $this->settings['inc_user_info'] ) ) {
302 211 $this->include_user_info = $this->settings['inc_user_info'];
@@ -307,11 +216,9 @@
307 216 * Set the is_single_recipient property
308 217 *
309 218 * @since 2.03.04
310 219 *
311 - * @param object $action
312 - *
313 - * @return void
220 + * @param $action
314 221 */
315 222 private function set_is_single_recipient( $action ) {
316 223 $args = array(
317 224 'form' => $this->form,
@@ -330,10 +237,8 @@
330 237 /**
331 238 * Set the charset
332 239 *
333 240 * @since 2.03.04
334 - *
335 - * @return void
336 241 */
337 242 private function set_charset() {
338 243 $this->charset = get_option( 'blog_charset' );
339 244 }
@@ -341,10 +246,8 @@
341 246 /**
342 247 * Set the content type
343 248 *
344 249 * @since 2.03.04
345 - *
346 - * @return void
347 250 */
348 251 private function set_content_type() {
349 252 if ( $this->is_plain_text ) {
350 253 $this->content_type = 'text/plain';
@@ -354,10 +257,8 @@
354 257 /**
355 258 * Set the subject
356 259 *
357 260 * @since 2.03.04
358 - *
359 - * @return void
360 261 */
361 262 private function set_subject() {
362 263 if ( empty( $this->settings['email_subject'] ) ) {
363 264 /* translators: %1$s: Form name, %2$s: Site name */
@@ -365,9 +266,8 @@
365 266 } else {
366 267 $this->subject = $this->settings['email_subject'];
367 268 }
368 269
369 - // This also replaces [sitename] shortcode in default.
370 270 $this->subject = FrmFieldsHelper::basic_replace_shortcodes( $this->subject, $this->form, $this->entry );
371 271
372 272 $args = array(
373 273 'form' => $this->form,
@@ -374,8 +274,9 @@
374 274 'entry' => $this->entry,
375 275 'email_key' => $this->email_key,
376 276 );
377 277 $this->subject = apply_filters( 'frm_email_subject', $this->subject, $args );
278 +
378 279 $this->subject = wp_specialchars_decode( strip_tags( stripslashes( $this->subject ) ), ENT_QUOTES );
379 280 }
380 281
381 282 /**
@@ -381,38 +282,27 @@
381 282 /**
382 283 * Set the email message
383 284 *
384 285 * @since 2.03.04
385 - *
386 - * @return void
387 286 */
388 287 private function set_message() {
389 - $this->message = $this->settings['email_message'];
288 + $this->message = FrmFieldsHelper::basic_replace_shortcodes( $this->settings['email_message'], $this->form, $this->entry );
390 289
391 - if ( ! $this->is_plain_text ) {
392 - // The decode is to support [default-html] shortcodes.
393 - $this->message = html_entity_decode( $this->message );
394 - }
395 -
396 - $this->message = FrmFieldsHelper::basic_replace_shortcodes( $this->message, $this->form, $this->entry );
397 290 $prev_mail_body = $this->message;
398 -
399 - // Make a copy to prevent changes by reference.
400 - $pass_entry = clone $this->entry;
401 - $mail_body = FrmEntriesHelper::replace_default_message(
291 + $pass_entry = clone $this->entry; // make a copy to prevent changes by reference
292 + $mail_body = FrmEntriesHelper::replace_default_message(
402 293 $prev_mail_body,
403 294 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'],
295 + 'id' => $this->entry->id,
296 + 'entry' => $pass_entry,
297 + 'plain_text' => $this->is_plain_text,
298 + 'user_info' => $this->include_user_info,
409 299 )
410 300 );
411 301
412 302 // Add the user info if it isn't already included
413 303 if ( $this->include_user_info && $prev_mail_body === $mail_body ) {
414 - $data = $this->entry->description;
304 + $data = $this->entry->description;
415 305 $mail_body .= "\r\n\r\n" . __( 'User Information', 'formidable' ) . "\r\n";
416 306 $this->maybe_add_ip( $mail_body );
417 307 $mail_body .= __( 'User-Agent (Browser/OS)', 'formidable' ) . ': ' . FrmEntriesHelper::get_browser( $data['browser'] ) . "\r\n";
418 308 $mail_body .= __( 'Referrer', 'formidable' ) . ': ' . $data['referrer'] . "\r\n";
@@ -419,39 +309,17 @@
419 309 }
420 310
421 311 $this->message = $mail_body;
422 312
313 + $this->message = do_shortcode( $this->message );
314 +
423 315 if ( $this->is_plain_text ) {
424 316 $this->message = wp_specialchars_decode( strip_tags( $this->message ), ENT_QUOTES );
425 - $this->message = str_replace( ' ', '', $this->message );
426 - } else {
427 - $this->add_autop();
428 317 }
429 318
430 319 $this->message = apply_filters( 'frm_email_message', $this->message, $this->package_atts() );
431 320 }
432 321
433 - /**
434 - * Runs message through autop, extracting the content inside body tag if it has <body>.
435 - *
436 - * @return void
437 - */
438 - private function add_autop() {
439 - $message = $this->message;
440 - preg_match( '/<body[^>]*>([\s\S]*?)<\/body>/', $message, $match );
441 -
442 - if ( ! empty( $match[1] ) ) {
443 - $this->message = str_replace( $match[1], trim( wpautop( $match[1] ) ), $message );
444 - } else {
445 - $this->message = trim( wpautop( $message ) );
446 - }
447 - }
448 -
449 - /**
450 - * @param string $mail_body
451 - *
452 - * @return void
453 - */
454 322 private function maybe_add_ip( &$mail_body ) {
455 323 if ( ! empty( $this->entry->ip ) ) {
456 324 $mail_body .= __( 'IP Address', 'formidable' ) . ': ' . $this->entry->ip . "\r\n";
457 325 }
@@ -460,11 +328,8 @@
460 328 /**
461 329 * Set the attachments for an email message
462 330 *
463 331 * @since 2.03.04
464 - * @since 5.0.16 added new action_id key to $args.
465 - *
466 - * @return void
467 332 */
468 333 private function set_attachments() {
469 334 $args = array(
470 335 'entry' => $this->entry,
@@ -469,9 +334,8 @@
469 334 $args = array(
470 335 'entry' => $this->entry,
471 336 'email_key' => $this->email_key,
472 337 'settings' => $this->settings,
473 - 'action_id' => $this->action_id,
474 338 );
475 339
476 340 $this->attachments = apply_filters( 'frm_notification_attachment', array(), $this->form, $args );
477 341 }
@@ -484,24 +348,28 @@
484 348 * @return bool|mixed|void
485 349 */
486 350 public function should_send() {
487 351 if ( ! $this->has_recipients() ) {
488 - return false;
352 + $send = false;
353 + } else {
354 +
355 + $filter_args = array(
356 + 'message' => $this->message,
357 + 'subject' => $this->subject,
358 + 'recipient' => $this->to,
359 + 'header' => $this->package_header(),
360 + );
361 +
362 + /**
363 + * Stop an email based on the message, subject, recipient,
364 + * or any information included in the email header
365 + *
366 + * @since 2.2.8
367 + */
368 + $send = apply_filters( 'frm_send_email', true, $filter_args );
489 369 }
490 370
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 );
371 + return $send;
504 372 }
505 373
506 374 /**
507 375 * Check if an email has any recipients
@@ -510,9 +378,13 @@
510 378 *
511 379 * @return bool
512 380 */
513 381 private function has_recipients() {
514 - return $this->to || $this->cc || $this->bcc;
382 + if ( empty( $this->to ) && empty( $this->cc ) && empty( $this->bcc ) ) {
383 + return false;
384 + } else {
385 + return true;
386 + }
515 387 }
516 388
517 389 /**
518 390 * Send an email
@@ -525,9 +397,8 @@
525 397 $this->remove_buddypress_filters();
526 398 $this->add_mandrill_filter();
527 399
528 400 $sent = false;
529 -
530 401 if ( count( $this->to ) > 1 && $this->is_single_recipient ) {
531 402 foreach ( $this->to as $recipient ) {
532 403 $sent = $this->send_single( $recipient );
533 404 }
@@ -559,15 +430,13 @@
559 430 )
560 431 );
561 432
562 433 $subject = $this->encode_subject( $this->subject );
563 - $sent = wp_mail( $recipient, $subject, $this->message, $header, $this->attachments );
564 434
435 + $sent = wp_mail( $recipient, $subject, $this->message, $header, $this->attachments );
436 +
565 437 if ( ! $sent ) {
566 - if ( is_array( $header ) ) {
567 - $header = implode( "\r\n", $header );
568 - }
569 -
438 + $header = 'From: ' . $this->from . "\r\n";
570 439 $recipient = implode( ',', (array) $recipient );
571 440 $sent = mail( $recipient, $subject, $this->message, $header );
572 441 }
573 442
@@ -585,13 +454,13 @@
585 454 */
586 455 private function package_header() {
587 456 $header = array();
588 457
589 - if ( $this->cc ) {
458 + if ( ! empty( $this->cc ) ) {
590 459 $header[] = 'CC: ' . implode( ',', $this->cc );
591 460 }
592 461
593 - if ( $this->bcc ) {
462 + if ( ! empty( $this->bcc ) ) {
594 463 $header[] = 'BCC: ' . implode( ',', $this->bcc );
595 464 }
596 465
597 466 $header[] = 'From: ' . $this->from;
@@ -605,9 +474,9 @@
605 474 * Get the userID field ID and key for email settings
606 475 *
607 476 * @since 2.03.04
608 477 *
609 - * @param int $form_id
478 + * @param $form_id
610 479 *
611 480 * @return array
612 481 */
613 482 private function get_user_id_args( $form_id ) {
@@ -616,9 +485,8 @@
616 485 'field_key' => '',
617 486 );
618 487
619 488 $user_id_args['field_id'] = FrmEmailHelper::get_user_id_field_for_form( $form_id );
620 -
621 489 if ( $user_id_args['field_id'] ) {
622 490 $user_id_args['field_key'] = FrmField::get_key_by_id( $user_id_args['field_id'] );
623 491 }
624 492
@@ -630,16 +498,16 @@
630 498 *
631 499 * @since 2.03.04
632 500 *
633 501 * @param string $value
634 - * @param array $user_id_args
502 + * @param array $user_id_args
635 503 *
636 504 * @return string
637 505 */
638 506 private function prepare_email_setting( $value, $user_id_args ) {
639 - if ( str_contains( $value, '[' . $user_id_args['field_id'] . ']' ) ) {
507 + if ( strpos( $value, '[' . $user_id_args['field_id'] . ']' ) !== false ) {
640 508 $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'] . ']' ) ) {
509 + } elseif ( strpos( $value, '[' . $user_id_args['field_key'] . ']' ) !== false ) {
642 510 $value = str_replace( '[' . $user_id_args['field_key'] . ']', '[' . $user_id_args['field_key'] . ' show="user_email"]', $value );
643 511 }
644 512
645 513 $value = FrmFieldsHelper::basic_replace_shortcodes( $value, $this->form, $this->entry );
@@ -645,10 +513,11 @@
645 513 $value = FrmFieldsHelper::basic_replace_shortcodes( $value, $this->form, $this->entry );
646 514
647 515 // Remove brackets and add a space in case there isn't one
648 516 $value = str_replace( '<', ' ', $value );
517 + $value = str_replace( array( '"', '>' ), '', $value );
649 518
650 - return str_replace( array( '"', '>' ), '', $value );
519 + return $value;
651 520 }
652 521
653 522 /**
654 523 * Extract the emails from cc and bcc. Allow separation by , or ;.
@@ -657,13 +526,19 @@
657 526 * @since 2.03.04
658 527 *
659 528 * @param string $emails
660 529 *
661 - * @return array|string Emails.
530 + * @return array|string $emails
662 531 */
663 532 private function explode_emails( $emails ) {
664 - $emails = $emails ? preg_split( '/(,|;)/', $emails ) : '';
665 - return is_array( $emails ) ? array_map( 'trim', $emails ) : trim( $emails );
533 + $emails = ( ! empty( $emails ) ? preg_split( '/(,|;)/', $emails ) : '' );
534 + if ( is_array( $emails ) ) {
535 + $emails = array_map( 'trim', $emails );
536 + } else {
537 + $emails = trim( $emails );
538 + }
539 +
540 + return $emails;
666 541 }
667 542
668 543 /**
669 544 * Format the recipients( to, cc, bcc)
@@ -672,9 +547,9 @@
672 547 *
673 548 * @return array
674 549 */
675 550 private function format_recipients( $recipients ) {
676 - if ( ! $recipients ) {
551 + if ( empty( $recipients ) ) {
677 552 return $recipients;
678 553 }
679 554
680 555 foreach ( $recipients as $key => $val ) {
@@ -682,24 +557,24 @@
682 557
683 558 if ( is_email( $val ) ) {
684 559 // If a plain email is used, no formatting is needed
685 560 continue;
686 - }
561 + } else {
562 + $parts = explode( ' ', $val );
563 + $email = end( $parts );
687 564
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;
565 + if ( is_email( $email ) ) {
566 + // If user enters a name and email
567 + $name = trim( str_replace( $email, '', $val ) );
568 + } else {
569 + // If user enters a name without an email
570 + unset( $recipients[ $key ] );
571 + continue;
572 + }
695 573 }
696 574
697 - // If user enters a name and email
698 - $name = trim( str_replace( $email, '', $val ) );
699 -
700 575 $recipients[ $key ] = $this->format_from_email( $name, $email );
701 - }//end foreach
576 + }
702 577
703 578 return $recipients;
704 579 }
705 580
@@ -720,14 +595,14 @@
720 595 } else {
721 596 list( $from_name, $from_email ) = $this->get_name_and_email_for_sender( $from );
722 597 }
723 598
724 - // If sending the email from a yahoo address, change it to the WordPress default
725 - if ( str_contains( $from_email, '@yahoo.com' ) ) {
599 + // if sending the email from a yahoo address, change it to the WordPress default
600 + if ( strpos( $from_email, '@yahoo.com' ) ) {
601 +
726 602 // Get the site domain and get rid of www.
727 603 $sitename = strtolower( FrmAppHelper::get_server_value( 'SERVER_NAME' ) );
728 -
729 - if ( str_starts_with( $sitename, 'www.' ) ) {
604 + if ( substr( $sitename, 0, 4 ) === 'www.' ) {
730 605 $sitename = substr( $sitename, 4 );
731 606 }
732 607
733 608 $from_email = 'wordpress@' . $sitename;
@@ -749,9 +624,9 @@
749 624 $reply_to = trim( $reply_to );
750 625
751 626 if ( ! is_email( $reply_to ) ) {
752 627 list( $name, $email ) = $this->get_name_and_email_for_sender( $reply_to );
753 - $reply_to = $this->format_from_email( $name, $email );
628 + $reply_to = $this->format_from_email( $name, $email );
754 629 }
755 630
756 631 return $reply_to;
757 632 }
@@ -759,17 +634,12 @@
759 634 /**
760 635 * Get only the email if the name and email have been combined
761 636 *
762 637 * @since 3.0.06
763 - *
764 - * @param string $name
765 - *
766 - * @return string
767 638 */
768 639 private function get_email_from_name( $name ) {
769 640 $email = trim( trim( $name, '>' ), '<' );
770 -
771 - if ( str_contains( $email, '<' ) ) {
641 + if ( strpos( $email, '<' ) !== false ) {
772 642 $parts = explode( '<', $email );
773 643 $email = trim( $parts[1], '>' );
774 644 }
775 645
@@ -801,16 +671,15 @@
801 671 }
802 672
803 673 /**
804 674 * @since 3.0.06
805 - *
806 - * @param string $name
807 - * @param string $email
808 - *
809 - * @return string
810 675 */
811 676 private function format_from_email( $name, $email ) {
812 - return '' !== $name ? $name . ' <' . $email . '>' : $email;
677 + if ( '' !== $name ) {
678 + $email = $name . ' <' . $email . '>';
679 + }
680 +
681 + return $email;
813 682 }
814 683
815 684 /**
816 685 * Remove phone numbers from To addresses
@@ -816,42 +685,38 @@
816 685 * Remove phone numbers from To addresses
817 686 * Send the phone numbers to the frm_send_to_not_email hook
818 687 *
819 688 * @since 2.03.04
820 - *
821 - * @return void
822 689 */
823 690 private function handle_phone_numbers() {
691 +
824 692 foreach ( $this->to as $key => $recipient ) {
825 - if ( '[admin_email]' === $recipient || is_email( $recipient ) ) {
826 - continue;
827 - }
693 + if ( '[admin_email]' !== $recipient && ! is_email( $recipient ) ) {
694 + $recipient = explode( ' ', $recipient );
828 695
829 - $recipient = explode( ' ', $recipient );
696 + if ( is_email( end( $recipient ) ) ) {
697 + continue;
698 + }
830 699
831 - if ( is_email( end( $recipient ) ) ) {
832 - continue;
700 + do_action(
701 + 'frm_send_to_not_email',
702 + array(
703 + 'e' => $recipient,
704 + 'subject' => $this->subject,
705 + 'mail_body' => $this->message,
706 + 'reply_to' => $this->reply_to,
707 + 'from' => $this->from,
708 + 'plain_text' => $this->is_plain_text,
709 + 'attachments' => $this->attachments,
710 + 'form' => $this->form,
711 + 'email_key' => $key,
712 + )
713 + );
714 +
715 + // Remove phone number from to addresses
716 + unset( $this->to[ $key ] );
833 717 }
834 -
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
853 - }//end foreach
718 + }
854 719 }
855 720
856 721 /**
857 722 * Package an array of FrmEmail properties
@@ -870,12 +735,10 @@
870 735 'subject' => $this->subject,
871 736 'message' => $this->message,
872 737 'attachments' => $this->attachments,
873 738 'plain_text' => $this->is_plain_text,
874 - 'email_key' => $this->email_key,
875 739 'form' => $this->form,
876 740 'entry' => $this->entry,
877 - 'email_style' => $this->settings['email_style'],
878 741 );
879 742 }
880 743
881 744 /**
@@ -881,10 +744,8 @@
881 744 /**
882 745 * Remove the Buddypress email filters
883 746 *
884 747 * @since 2.03.04
885 - *
886 - * @return void
887 748 */
888 749 private function remove_buddypress_filters() {
889 750 remove_filter( 'wp_mail_from', 'bp_core_email_from_address_filter' );
890 751 remove_filter( 'wp_mail_from_name', 'bp_core_email_from_name_filter' );
@@ -894,10 +755,8 @@
894 755 * Add Mandrill line break filter
895 756 * Remove line breaks in HTML emails to prevent conflicts with Mandrill
896 757 *
897 758 * @since 2.03.04
898 - *
899 - * @return void
900 759 */
901 760 private function add_mandrill_filter() {
902 761 if ( ! $this->is_plain_text ) {
903 762 add_filter( 'mandrill_nl2br', 'FrmEmailHelper::remove_mandrill_br' );
@@ -907,10 +766,8 @@
907 766 /**
908 767 * Remove Mandrill line break filter
909 768 *
910 769 * @since 2.03.04
911 - *
912 - * @return void
913 770 */
914 771 private function remove_mandrill_filter() {
915 772 remove_filter( 'mandrill_nl2br', 'FrmEmailHelper::remove_mandrill_br' );
916 773 }
@@ -923,9 +780,9 @@
923 780 * @return string
924 781 */
925 782 private function encode_subject( $subject ) {
926 783 if ( apply_filters( 'frm_encode_subject', false, $subject ) ) {
927 - return '=?' . $this->charset . '?B?' . base64_encode( $subject ) . '?=';
784 + $subject = '=?' . $this->charset . '?B?' . base64_encode( $subject ) . '?=';
928 785 }
929 786
930 787 return $subject;
931 788 }