
How to Configure SMTP Email Sending in WordPress Using SendGrid
Introduction
By default, WordPress uses the server's mail() function to send emails. While this may work for basic email delivery, it does not guarantee email deliverability, and important transactional emails (e.g., contact form submissions or password reset emails) may be flagged as spam or fail to deliver. To ensure reliable email delivery, we need to configure an SMTP (Simple Mail Transfer Protocol) service. This guide outlines the step-by-step process to set up SMTP email sending using SendGrid, ensuring reliable delivery of emails sent by your WordPress website.
This is an old trick in WordPress to configure SMTP without purchasing a SendGrid plan, and the process leverages the Single Sender feature of SendGrid.
Step 1: Create a SendGrid Account
-
Visit the SendGrid website and click Sign Up for Free.
-
Complete the registration form with the following details:
-
Email Address: Use your desired email address.
-
Password: Create a strong password.
-
Username: Choose a username.
-
Verify your email address by clicking the verification link sent to your inbox.
-
Once verified, log in to your SendGrid account.
-
Navigate to Settings > API Keys.
-
Click Create API Key, provide a name (e.g., WordPress SMTP), and select the necessary permissions (full access is recommended).
-
Copy the API key provided. Important: This key will only be shown once. Save it in a secure location (e.g., a password manager).
Step 2: Configure SendGrid in WordPress
-
Log in to your WordPress admin dashboard.
-
Install the WP Mail SMTP plugin:
-
Go to Plugins > Add New.
-
Search for "WP Mail SMTP" and click Install Now, then Activate.
-
Navigate to WP Mail SMTP > Settings.
-
Under the Mailer section, select SendGrid.
-
Enter the following details:
-
From Email: Use the email address you registered and verified with SendGrid (e.g., hello@a11yalt.ai).
-
From Name: Enter the name you want to appear as the sender.
-
API Key: Paste the API key you copied from SendGrid.
-
Save the settings.
-
Test the configuration by navigating to WP Mail SMTP > Tools > Email Test, and sending a test email to verify the setup.
Step 3: Configure Single Sender Email in SendGrid
SendGrid is a robust email platform that requires a plan to use for email marketing. However, it allows us to configure a Single Sender, which enables sending emails to a single verified email account. We can leverage this feature to use SMTP for sending contact form submissions or any other transactional emails to a single email, such as the general WordPress email.
-
Log in to your SendGrid account.
-
Navigate to Settings > Sender Authentication.
-
Under Single Sender Verification, click Get Started.
-
Enter the following details:
-
From Name: Use your name or your company name.
-
From Email: Enter the email address used for the WordPress configuration (e.g., hello@a11yalt.ai).
-
Address and City: Enter valid contact details.
-
Click Save.
-
Check your inbox for a verification email from SendGrid and confirm the email address.
-
Once verified, this email address can now send emails using the SMTP configuration.
Step 4: Configure Contact Form 7 or Other Plugins
-
Open the settings for your contact form plugin (e.g., Contact Form 7).
-
Update the Mail settings as follows:
-
To Email: Use the same email address configured with SendGrid (e.g., hello@a11yalt.ai).
-
From Email: Match this with the verified Single Sender Email (e.g., hello@a11yalt.ai).
-
Reply-To: Set this to the verified Single Sender Email (e.g., hello@a11yalt.ai).
-
Additional Headers: None required.
-
Save the settings and test the form by submitting a message.
Note: The Reply-To field often comes blank initially and does not show an error. However, it must be updated to the Single Sender Email (e.g., hello@a11yalt.ai). This issue may appear after a few attempts or when the configuration is edited.
Step 5: Install Email Log Plugin for Debugging
The WP Mail SMTP plugin requires a Pro plan for email logging. To enable logging without upgrading, we can use the SMTP Post plugin instead:
-
Install the SMTP Post plugin:
-
Go to Plugins > Add New.
-
Search for "SMTP Post" and click Install Now, then Activate.
-
Use this plugin to check the email logs and verify that emails are sent successfully.
-
Note: The SMTP Post plugin may conflict with WP Mail SMTP. To avoid issues:
-
Keep SMTP Post deactivated when not in use.
-
Activate it only for debugging purposes.
Step 6: Verify Email Delivery
-
Submit a test form or trigger a transactional email (e.g., password reset).
-
Check the logs in SMTP Post to confirm successful email sending.
-
Verify that the email has been delivered by checking the recipient inbox.
Important Notes
-
Ensure the From Email in all plugins matches the verified Single Sender Email in SendGrid.
-
The WordPress General Email Address (under Settings > General) must also match the SendGrid email.
-
The Contact Form 7 (CF7) email settings must also match the Single Sender Email.
By following these steps, your WordPress website will be able to reliably send emails via SMTP using SendGrid, ensuring better deliverability and avoiding common pitfalls of the default mail() function.