Home / Admin / Custom Gmail SMTP
Duplicate Snippet

Embed Snippet on Your Site

Custom Gmail SMTP

Add SMTP layer to default PHP mail. Require additional Gmail configurations. Must update default "From" WP mail address with custom Gmail SMTP details for reliable delivery. Must also match notification setting email on the site for internal site notification updates to work.

Code Preview
php
<?php
// Custom Gmail SMTP / Kiri Vadivelu / 2026
add_action('phpmailer_init', 'send_gmail_smtp');
function send_gmail_smtp($phpmailer) {
    $phpmailer->isSMTP();
    $phpmailer->Host       = 'smtp.gmail.com';
    $phpmailer->SMTPAuth   = true;
    $phpmailer->Port       = 587; // Use 465 for SSL, 587 for TLS
    $phpmailer->SMTPSecure = 'tls'; // 'ssl' for port 465
    $phpmailer->Username   = '[email protected]';
    $phpmailer->Password   = 'your-app-password'; // App password only
    $phpmailer->From       = '[email protected]';
    $phpmailer->FromName   = 'Your Name';
}     

Comments

Add a Comment