'POST', 'body' => [ 'client_id' => $client_id, 'client_secret' => $client_secret, 'code' => $code, 'redirect_uri' => $redirect_uri, 'grant_type' => 'authorization_code' ] ]; if ($state === 'google') { $token_url = 'https://oauth2.googleapis.com/token'; } elseif ($state === 'microsoft') { $token_url = 'https://login.microsoftonline.com/common/oauth2/v2.0/token'; } if (empty($token_url)) return; $response = wp_remote_post($token_url, $args); if ( !is_wp_error($response) ) { $body = json_decode(wp_remote_retrieve_body($response), true); if ( isset($body['refresh_token']) ) { $settings['optOAuthRefreshToken_' . $state] = AIO_Crypto::encrypt($body['refresh_token']); update_option('aio_options', $settings); // Redirect to clean URL wp_redirect($redirect_uri); exit; } } } public function w2wSmtpCheckHandler(){ check_ajax_referer( 'aio-smtp-check-nonce', 'security' ); if ( ! current_user_can( 'manage_options' ) ) { wp_send_json_error( __( 'You do not have sufficient permissions to access this page.', 'aio' ) ); } $recipient = sanitize_email($_POST['your_email']); if ( ! is_email( $recipient ) ) { wp_send_json_error( __( 'Invalid email address.', 'aio' ) ); } $subject = __('AIO Tool: SMTP Test Connection', 'aio' ); $headers = array('Content-Type: text/html; charset=UTF-8'); $message = '

SMTP Test Successful!

Hello,

This is a test email sent from your website using AIO Tools.

If you are reading this, it means your SMTP configuration is working perfectly.

Sent via: ' . site_url() . '

Time: ' . current_time('Y-m-d H:i:s') . '

© ' . date('Y') . ' AIO Tools. All rights reserved.
'; // Inject PHPMailer debug interceptor add_action( 'phpmailer_init', function( $phpmailer ) { $phpmailer->SMTPDebug = 2; // Enable verbose debug output $phpmailer->Debugoutput = 'html'; }); ob_start(); try { $result = wp_mail($recipient, $subject, $message, $headers); $debug_log = ob_get_clean(); $debug_log = strip_tags(str_replace("
\n", "\n", $debug_log)); // Clean up HTML formatting from Debugoutput='html' if ( ! $result ) { wp_send_json_error([ 'debug_log' => $debug_log ?: 'Mailer Error: Failed to send via wp_mail. (Check PHP error log)' ]); } else { wp_send_json_success([ 'debug_log' => $debug_log ?: 'Sent successfully via wp_mail. (Native mail() may not produce debug logs)' ]); } } catch (Exception $e) { $debug_log = ob_get_clean(); wp_send_json_error([ 'debug_log' => $debug_log . "\nException: " . $e->getMessage() ]); } } }