| @@ -424,88 +424,91 @@ | ||
| 424 | 424 | * |
| 425 | 425 | * @param string $emails |
| 426 | 426 | * @return string |
| 427 | 427 | */ |
| 428 | - public function validate_emails( $emails ) { | |
| 428 | + public function validate_emails( $emails ) { | |
| 429 | 429 | |
| 430 | - $emails = str_replace(';', ',', $emails); | |
| 430 | + $emails = str_replace( ';', ',', $emails ); | |
| 431 | 431 | |
| 432 | - if ( !is_array( $emails ) ) | |
| 433 | - $emails = explode( ',', $emails ); | |
| 432 | + if ( ! is_array( $emails ) ) { | |
| 433 | + $emails = explode( ',', $emails ); | |
| 434 | + } | |
| 434 | 435 | |
| 435 | - $emails_list = array(); | |
| 436 | - foreach ( (array) $emails as $recipient ) { | |
| 437 | - | |
| 438 | - // Break $recipient into name and address parts if in the format "Foo <bar@baz.com>" | |
| 439 | - $recipient_name = ''; | |
| 440 | - if( preg_match( '/(.*)<(.+)>/', $recipient, $matches ) ) { | |
| 441 | - if ( count( $matches ) == 3 ) { | |
| 442 | - $recipient_name = $matches[1]; | |
| 443 | - $recipient = $matches[2]; | |
| 444 | - } | |
| 445 | - } else { | |
| 446 | - // Check about correct format of email | |
| 447 | - if( preg_match( '/([\w\.\-_]+)?\w+@[\w\-_]+(\.\w+){1,}/im', $recipient, $matches ) ) { // FixIn: 8.7.7.2. | |
| 448 | - $recipient = $matches[0]; | |
| 449 | - } | |
| 450 | - } | |
| 436 | + $emails_list = array(); | |
| 437 | + foreach ( (array) $emails as $recipient ) { | |
| 451 | 438 | |
| 452 | - //$recipient_name = str_replace('"', '', $recipient_name); | |
| 453 | - $recipient_name = trim( wp_specialchars_decode( esc_html( stripslashes( $recipient_name ) ), ENT_QUOTES ) ); | |
| 454 | - | |
| 455 | - $emails_list[] = ( empty( $recipient_name ) ? '' : $recipient_name . ' ' ) | |
| 456 | - . '<' . sanitize_email( $recipient ) . '>'; | |
| 439 | + // Break $recipient into name and address parts if in the format "Foo <bar@baz.com>". | |
| 440 | + $recipient_name = ''; | |
| 441 | + if ( preg_match( '/(.*)<(.+)>/', $recipient, $matches ) ) { | |
| 442 | + if ( count( $matches ) == 3 ) { | |
| 443 | + $recipient_name = $matches[1]; | |
| 444 | + $recipient = $matches[2]; | |
| 445 | + } | |
| 446 | + } else { | |
| 447 | + // Check about correct format of email. | |
| 448 | + if ( preg_match( '/([\w\.\-_]+)?\w+@[\w\-_]+(\.\w+){1,}/im', $recipient, $matches ) ) { // FixIn: 8.7.7.2. | |
| 449 | + $recipient = $matches[0]; | |
| 450 | + } | |
| 451 | + } | |
| 452 | + | |
| 453 | + $recipient_name = trim( wp_specialchars_decode( esc_html( stripslashes( $recipient_name ) ), ENT_QUOTES ) ); | |
| 454 | + // FixIn: 10.15.5.1. | |
| 455 | + //$emails_list[] = ( empty( $recipient_name ) ? '' : $recipient_name . ' ' ) . '<' . sanitize_email( $recipient ) . '>'; | |
| 456 | + $sanitized_email_address = sanitize_email( $recipient ); | |
| 457 | + if ( ! empty( $sanitized_email_address ) ) { | |
| 458 | + $emails_list[] = '<' . sanitize_email( $recipient ) . '>'; | |
| 459 | + } | |
| 460 | + | |
| 461 | + } | |
| 462 | + | |
| 463 | + $emails_list = implode( ',', $emails_list ); | |
| 464 | + | |
| 465 | + return $emails_list; | |
| 457 | 466 | } |
| 458 | - | |
| 459 | - $emails_list = implode( ',', $emails_list ); | |
| 460 | 467 | |
| 461 | - return $emails_list; | |
| 462 | - } | |
| 463 | 468 | |
| 464 | - | |
| 465 | - /** | |
| 466 | - * Make Email Sending by using wp_mail standard function. | |
| 467 | - * | |
| 468 | - * @param string $to - Email | |
| 469 | - * @param array $replace - accociated array of values to replace in email Body and Subject. Exmaple: array( 'name' => 'Jo', 'secondname' => 'Smith' ) | |
| 470 | - * @return boolean Sent or Failed to send. | |
| 471 | - */ | |
| 472 | - public function send( $to = '', $replace = array() ) { | |
| 469 | + /** | |
| 470 | + * Make Email Sending by using wp_mail standard function. | |
| 471 | + * | |
| 472 | + * @param string $to - Email | |
| 473 | + * @param array $replace - accociated array of values to replace in email Body and Subject. Exmaple: array( 'name' => 'Jo', 'secondname' => 'Smith' ) | |
| 474 | + * | |
| 475 | + * @return boolean Sent or Failed to send. | |
| 476 | + */ | |
| 477 | + public function send( $to = '', $replace = array() ) { | |
| 473 | 478 | |
| 474 | - $return = false; | |
| 475 | - | |
| 476 | -// if ( empty( $to ) ) | |
| 477 | -// return $return; | |
| 478 | - | |
| 479 | - $this->sending = true; | |
| 479 | + $return = false; | |
| 480 | 480 | |
| 481 | + // if ( empty( $to ) ) { return $return; } //. | |
| 481 | 482 | |
| 482 | - $this->set_replace( $replace ); | |
| 483 | + $this->sending = true; | |
| 483 | 484 | |
| 484 | - $to = $this->validate_emails( $to ); | |
| 485 | + $this->set_replace( $replace ); | |
| 485 | 486 | |
| 486 | - $subject = $this->get_subject(); | |
| 487 | - $message = $this->get_content(); | |
| 488 | - $headers = $this->get_headers(); | |
| 489 | - $attachments = $this->get_attachments(); | |
| 490 | -//debuge('In email', htmlentities($to), $subject, htmlentities($message), $headers, $attachments) ; | |
| 491 | - $is_send_email = true; | |
| 492 | - | |
| 493 | - $is_send_email = apply_filters( 'wpbc_email_api_is_allow_send', $is_send_email, $this->id, $this->fields_values ); | |
| 494 | - | |
| 495 | - if ( $is_send_email ) { | |
| 496 | - $to = apply_filters( 'wpbc_email_api_send_field_to', $to ); // FixIn: 8.1.3.1. | |
| 497 | - // FixIn: 8.5.2.22. | |
| 498 | - if ( ! empty( $to ) ) { | |
| 499 | -// debuge( '$to, $subject, $message, $headers, $attachments',htmlspecialchars($to), htmlspecialchars($subject), htmlspecialchars($message), htmlspecialchars($headers), htmlspecialchars($attachments)); | |
| 500 | -//debuge( debug_backtrace() ); | |
| 501 | - $return = wp_mail( $to, $subject, $message, $headers, $attachments ); | |
| 502 | - } | |
| 503 | - } | |
| 487 | + $to = $this->validate_emails( $to ); | |
| 504 | 488 | |
| 505 | - $this->sending = false; | |
| 489 | + $subject = $this->get_subject(); | |
| 490 | + $message = $this->get_content(); | |
| 491 | + $headers = $this->get_headers(); | |
| 492 | + $attachments = $this->get_attachments(); | |
| 493 | + // FixIn: 10.15.5.2. | |
| 494 | + $attachments = apply_filters( 'wpbc_email_attachments', $attachments, $this->id, $replace ); | |
| 506 | 495 | |
| 507 | - // Send Copy to admin email | |
| 496 | + $is_send_email = true; | |
| 497 | + | |
| 498 | + $is_send_email = apply_filters( 'wpbc_email_api_is_allow_send', $is_send_email, $this->id, $this->fields_values ); | |
| 499 | + | |
| 500 | + if ( $is_send_email ) { | |
| 501 | + $to = apply_filters( 'wpbc_email_api_send_field_to', $to ); // FixIn: 8.1.3.1. | |
| 502 | + // FixIn: 8.5.2.22. | |
| 503 | + if ( ! empty( $to ) ) { | |
| 504 | + $return = wp_mail( $to, $subject, $message, $headers, $attachments ); | |
| 505 | + } | |
| 506 | + } | |
| 507 | + | |
| 508 | + $this->sending = false; | |
| 509 | + | |
| 510 | + // Send Copy to admin email. | |
| 508 | 511 | if ( |
| 509 | 512 | ( isset( $this->fields_values['copy_to_admin'] ) ) |
| 510 | 513 | && ( $this->fields_values['copy_to_admin'] == 'On' ) |
| 511 | 514 | ){ |