WordPress

How to configure SMTP on WordPress with and without a plugin?

If you try to perform a function on the WordPress website and that function requires email verification, WordPress is not sending the email or facing any other trouble. You might wonder why all this happening, is any problem with your WordPress website? Here the actual problem is that WordPress is not configured to send emails. In this article, we’ll understand how to configure WordPress to send emails.

Why should SMTP send emails using WordPress?

WordPress, by default, is configured to use PHP functions to handle email service. But in VPS and Cloud hosting, this PHP mail function is not configured, and some shared hosting providers disable this function to reduce load and spam. That’s why you may face problems while sending or receiving emails using your WordPress website.

Configure WordPress to send email using SMTP server

To enhance the email functionality of WordPress, you can implement the Simple Mail Transfer Protocol or SMTP server to WordPress. There are many SMTP providers like MailGun, Sendinblue, Mailgun, Sendgrid etc.

Configure SMTP on WordPress without using a plugin.

In this method, you’ve to configure SMTP on WordPress manually by editing the wp-config.php and function.php file. If you’ve some technical skills, then this can be the best method for configuring SMTP.

WordPress configuration File (wp-config.php file): You can locate this file under the root directory of the WordPress website. Edit this using file manager, FTP server, or SSH terminal.

Theme Function File (function.php): You can locate this file in the Theme of the WordPress website. You can edit this file from the WordPress dashboard through Appearance > Theme Editor.

Email SMTP settings in wp-config.php.

Paste the following files into the wp-config.php file of your WordPress website. We place all the SMTP server settings in the wp-config file for security.

// SMTP email settings
define( 'SMTP_username', 'youremail@gmail.com' );  // username of host like Gmail
define( 'SMTP_password', 'gmail-app-password' );   // password for login into the App
define( 'SMTP_server', 'smtp.gmail.com' );     // SMTP server address
define( 'SMTP_FROM', 'youremail@example.com' );   // Your Business Email Address
define( 'SMTP_NAME', 'SEO Neurons' );   //  Business From Name
define( 'SMTP_PORT', '587' );     // Server Port Number
define( 'SMTP_SECURE', 'tls' );   // Encryption - ssl or tls
define( 'SMTP_AUTH', true );  // Use SMTP authentication (true|false)
define( 'SMTP_DEBUG',   0 );  // for debugging purposes only

In the above files, you’ve to change the red color values with your values. If you don’t know where you can find all these SMTP server settings, read this article till the end.

Theme functions file (functions.php)

You’ve to add the following lines to the theme functions file. Access Theme functions file through WordPress dashboard > Appearance > Theme Editor.

add_action( 'phpmailer_init', 'my_phpmailer_smtp' );
function my_phpmailer_smtp( $phpmailer ) {
    $phpmailer->isSMTP();     
    $phpmailer->Host = SMTP_server;  
    $phpmailer->SMTPAuth = SMTP_AUTH;
    $phpmailer->Port = SMTP_PORT;
    $phpmailer->Username = SMTP_username;
    $phpmailer->Password = SMTP_password;
    $phpmailer->SMTPSecure = SMTP_SECURE;
    $phpmailer->From = SMTP_FROM;
    $phpmailer->FromName = SMTP_NAME;
}

You don’t need to make any changes in the above file, copy the code, and paste it into the function.php file. Save the settings. We advise you to use a child theme; else, these changes will be removed on the theme update.

After making the above changes, you can try sending an email using the contact us form.

Configure SMTP with the help of a plugin.

To send emails using the SMTP service, you need to install the SMTP plugin. Many plugins are available in the WordPress plugin store, like Easy WP SMTP, Post SMTP Mailer with Email Log, and many more. You can install any from the list, but Post SMTP Mailer with Email log provides a more user-friendly experience with email log service.

Install Post SMTP Mail with email log to your WordPress website; follow this guide to install a WordPress plugin. There will be a setup wizard open up or access it from the WordPress dashboard and library.

Configure the Plugin for WordPress Emails.

To configure the SMTP plugin for WordPress, scroll the WordPress dashboard>Post SMTP and then click on “Show All Settings”.

setup-wizard-wp

When you click on show all settings> it will display the current email mailer configuration used by the WordPress website.

Account setup SMTP configuration

In account settings, you’ll be asked to fill up server settings. Read this complete article to know where you can find all these settings.

  1. Choose the type as SMTP
  2. Select mailer type: Post SMTP
  3. Outgoing mail server hostname: You can find this value from your email service provider. Here, we’re using Gmail as an SMTP server; hence the value will be smtp.gmail.com.
  4. Outgoing service mail port: 587;
  5. Envelop from email: The email address you want to use to send emails from the WordPress website,
  6. Security: STARTTLS,
  7. Authentification: Login;
  8. User Name: Your Email Address
  9. Password: Password of the email address (for Gmail, you’ve to generate an app password, the guide provided below).
  10. Save the changes.

WordPress is now configured to send emails. You can now reset or change email addresses or authors, admin, and receive notification through email when someone comments on the blog posts.

If you can’t find the server details, you can further follow this guide.

Find SMTP servers for Emails.

You can use the SMTP server to send emails using WordPress. This SMTP server can be set up using:

  • cPanel of the hosting provider,
  • using Gmail(free SMTP but can’t use for heavy mails),
  • Other SMTP service providers.

Setup SMTP using cPanel.

You can use this service if your hosting provider provides cPanel to manage the WordPress website. For this, you’ve to log in to the hosting provider and visit the cPanel section. And create a Business email address to send emails of WordPress.

cPanel SMTP server setting

You can check SMTP settings of your email in cPanel, scroll to email accounts>connected devices>and outgoing server settings. These are outgoing SMTP server settings.

Use SMTP server of Gmail.

You can use the SMTP server of Gmail to send emails using your WordPress website.

  • SMTP server: smtp.gmail.com
  • Port for TLS/STARTTLS: 587
  • SMTP username: Gmail Email Address,
  • Password: You can generate an App password. Using this Google App Password Link. Or go to Google Account Settings>Security>App Password.

You can check Gmail SMTP server settings in this article. But for heavy uses, you can’t use the SMTP server of Gmail. You can also create a Business email address using Gmail for free.

Final Words

This is how we can configure SMTP in WordPress to send emails. I hope this article helped you or resolved the email issue. In case of any doubt, query or feedback, feel free to ask in the comment section provided below.

Ashok Kumar

Ashok Kumar working in the Search Engine Optimization field since 2015. And worked on many successful projects since then. He shares the real-life experience of best SEO practices with his followers on seoneurons.com. You also can learn Advance level SEO for WordPress, Blogger, or any other blogging platform. Stay tuned.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *