array( 'label' => __( 'SMTP Host', 'noorsmtp' ), 'type' => 'text', ), 'smtp_port' => array( 'label' => __( 'SMTP Port', 'noorsmtp' ), 'type' => 'number', 'default' => 587, ), 'smtp_encryption' => array( 'label' => __( 'Encryption', 'noorsmtp' ), 'type' => 'select', 'options' => array( 'tls' => __( 'TLS', 'noorsmtp' ), 'ssl' => __( 'SSL', 'noorsmtp' ), 'none' => __( 'None', 'noorsmtp' ), ), 'default' => 'tls', ), 'smtp_auth' => array( 'label' => __( 'Requires Authentication', 'noorsmtp' ), 'type' => 'checkbox', 'default' => true, ), 'smtp_username' => array( 'label' => __( 'SMTP Username', 'noorsmtp' ), 'type' => 'text', ), 'smtp_password' => array( 'label' => __( 'SMTP Password', 'noorsmtp' ), 'type' => 'password', ), ); } /** * {@inheritDoc} */ public function configure_phpmailer( $phpmailer, array $settings ) { $phpmailer->isSMTP(); $host = isset( $settings['smtp_host'] ) ? sanitize_text_field( $settings['smtp_host'] ) : ''; $host = preg_replace( '#^(https?|ssl|tls)://#i', '', trim( $host ) ); $phpmailer->Host = $host; $phpmailer->Port = isset( $settings['smtp_port'] ) ? absint( $settings['smtp_port'] ) : 587; $phpmailer->SMTPAuth = ! empty( $settings['smtp_auth'] ); $phpmailer->Timeout = 10; $encryption = isset( $settings['smtp_encryption'] ) ? $settings['smtp_encryption'] : 'tls'; if ( 'none' === $encryption ) { $phpmailer->SMTPSecure = ''; $phpmailer->SMTPAutoTLS = false; } else { $phpmailer->SMTPSecure = $encryption; } if ( $phpmailer->SMTPAuth ) { $phpmailer->Username = isset( $settings['smtp_username'] ) ? sanitize_text_field( $settings['smtp_username'] ) : ''; $phpmailer->Password = isset( $settings['smtp_password'] ) ? $settings['smtp_password'] : ''; } // Prevent SSL verification failures on local development servers, Windows, or self-signed certs. $default_ssl_options = array( 'ssl' => array( 'verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true, ), ); /** * Filter PHPMailer SMTP connection options. * * @since 1.2.0 * @param array $options SSL stream context options. */ $phpmailer->SMTPOptions = apply_filters( 'noorsmtp_smtp_options', $default_ssl_options ); } }