If you're having issues sending emails from your website (contact forms, reset password, etc.), setting up Gmail SMTP is a reliable alternative. This guide will walk you through the step-by-step process to use your Gmail account to send emails from your site.
Requirements
-
A Gmail or Google Workspace (G Suite) account
-
Access to your web hosting control panel (cPanel or WHM)
-
SMTP support in your script or app (most CMS platforms support this)
-
"Less secure apps" access enabled (for Gmail personal accounts), or an App Password if 2FA is enabled
Step 1: Enable SMTP Access in Gmail
Option 1: For accounts without 2FA
-
Scroll down to "Less secure app access"
-
Turn Allow less secure apps to ON
⚠️ Google may phase this out. Use Option 2 if you can't find it.
Option 2: For accounts with 2FA enabled (recommended)
You’ll need to create an App Password.
-
Make sure 2-Step Verification is enabled
-
Click on App Passwords
-
Select App → Other (Custom name) → e.g., My Website
-
Click Generate
-
Copy the 16-character app password
⚙️ Step 2: Configure SMTP in Your Application
Use the following SMTP settings in your app or website:
Setting | Value |
---|---|
SMTP Host | smtp.gmail.com |
SMTP Port | 587 (TLS) or 465 (SSL) |
Encryption | TLS or SSL |
SMTP Username | Your full Gmail address |
SMTP Password | Your Gmail password or App Password |
From Email | Your Gmail address |
From Name | Anything you prefer |
✅ Port 587 with TLS is the most commonly used.
Example Configuration in WordPress (Using WP Mail SMTP)
-
Install the WP Mail SMTP plugin
-
Go to WP Mail SMTP > Settings
-
Choose Mailer: "Other SMTP"
-
Enter:
-
SMTP Host:
smtp.gmail.com
-
SMTP Port:
587
-
Encryption:
TLS
-
SMTP Username: your Gmail address
-
SMTP Password: your Gmail/App password
-
-
Save and test!
Example Configuration in PHP
⚠️ Common Issues & Fixes
Issue | Solution |
---|---|
SMTP connect() failed |
Use the correct port (587 or 465) and check your firewall |
Username and Password not accepted |
Ensure your Gmail password/App Password is correct |
Gmail blocks the sign-in attempt | Check Gmail security alerts or use App Password |
Port 25 blocked | Use port 587 or 465 instead |
Email goes to spam | Set proper “From Name” and SPF records |
Test the SMTP Connection (Optional)
From your hosting terminal:
Or use PHP’s mail()
test or WP Mail SMTP’s test email feature.
✅ Final Tips
-
Use App Passwords if 2FA is enabled — they are more secure.
-
Never share your Gmail credentials in public scripts or repos.
-
For heavy email sending, consider Gmail API or use a transactional email service like Mailgun, SendGrid, or Amazon SES.