65535 ) { $smtp_port = 587; } // Normalize encryption value; map 'none' to empty string. $smtp_security_raw = strtolower( trim( (string) Settings::get_option( 'encryption_type' ) ) ); $smtp_security = ( 'none' === $smtp_security_raw ) ? '' : $smtp_security_raw; $smtp_username = trim( (string) Settings::get_option( 'smtp_username' ) ); $smtp_password = (string) Settings::get_option( 'smtp_password' ); $smtp_authentication = ( '' !== $smtp_username && '' !== $smtp_password ); $smtp_bypass_ssl_verification = (bool) Settings::get_option( 'smtp_bypass_ssl_verification' ); // Do nothing if host or password is empty // if ( empty( $smtp_host ) || empty( $smtp_password ) ) { // return; // } // Maybe override FROM email and/or name if the sender is "WordPress ", the default from WordPress core and not yet overridden by another plugin. // $from_name = $phpmailer->FromName; // $from_email_beginning = substr( $phpmailer->From, 0, 9 ); // Get the first 9 characters of the current FROM email. // if ( $smtp_force_from ) { // $phpmailer->FromName = $smtp_default_from_name; // $phpmailer->From = $smtp_default_from_email; // } else { // if ( 'WordPress' === $from_name && ! empty( $smtp_default_from_name ) ) { // $phpmailer->FromName = $smtp_default_from_name; // } // if ( 'WordPress' === $from_email_beginning && ! empty( $smtp_default_from_email ) ) { // $phpmailer->From = $smtp_default_from_email; // } // }. // Validate/sanitize sender fields. $from_email = \sanitize_email( (string) Settings::get_option( 'from_email' ) ); if ( ! empty( $from_email ) && \is_email( $from_email ) ) { $phpmailer->From = $from_email; $phpmailer->Sender = $from_email; } $from_email_name = \sanitize_text_field( (string) Settings::get_option( 'from_email_name' ) ); if ( ! empty( $from_email_name ) ) { $phpmailer->FromName = $from_email_name; } // Only attempt to send via SMTP if all the required info is present. Otherwise, use default PHP Mailer settings as set by wp_mail(). if ( ! empty( $smtp_host ) && ! empty( $smtp_port ) ) { // Send using SMTP. $phpmailer->isSMTP(); if ( $smtp_authentication ) { $phpmailer->SMTPAuth = true; } else { $phpmailer->SMTPAuth = false; } // Set some other defaults. $phpmailer->XMailer = ADVAN_NAME . ' - a WordPress plugin'; $phpmailer->Host = $smtp_host; $phpmailer->Port = $smtp_port; // Validate SMTP security value before assigning. $allowed_smtp_security = array( 'ssl', 'tls', '' ); if ( in_array( $smtp_security, $allowed_smtp_security, true ) ) { $phpmailer->SMTPSecure = $smtp_security; } else { $phpmailer->SMTPSecure = ''; } if ( $smtp_authentication ) { $phpmailer->Username = trim( $smtp_username ); $phpmailer->Password = trim( $smtp_password ); } } // If verification of SSL certificate is bypassed. // Reference: https://www.php.net/manual/en/context.ssl.php & https://stackoverflow.com/a/30803024 . if ( $smtp_bypass_ssl_verification ) { $phpmailer->SMTPOptions = array( 'ssl' => array( 'verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true, ), ); } // If debug mode is enabled, send debug info (SMTP::DEBUG_CONNECTION) to WordPress debug.log file set in wp-config.php. // Reference: https://github.com/PHPMailer/PHPMailer/wiki/SMTP-Debugging // if ( $smtp_debug ) { // $phpmailer->SMTPDebug = 4;. // $phpmailer->Debugoutput = 'error_log';. // } } } }