Using SMTP to send emails from WordPress

By default email from your WordPress site will be sent using PHP mail by your hosting server. In theory, this is quick and requires no setup from you. However, emails sent this way are not authenticated - see our guide on mail authentication - SPF, DKIM and DMARC.

This lack of authentication may mean your emails will be blocked before they reach their intended recipient.

The way around this is to use an authenticated method - in this guide, we discuss setting up SMTP authentication using a cPanel mail account.

In WordPress, this is accomplished by the use of a plugin. We suggest WP Mail SMTP (external link opens in a new window).

You'll need to be logged in to WordPress as an Administrator, or have sufficient privileges to be able to install a plugin.

You will need the login and configuration details of a cPanel mailbox to use in the following guide - this will ultimately be where your emails will be sent from. If you don't have those you can either find the configuration details for an existing mail account or create a new account.

  1. From the WordPress dashboard, select Plugins > Add New or from the Plugins screen click the Add New button.
  2. Start typing wp mail SMTP into the search box and the correct plugin should show up in the results.
  3. Click the Install Now button.
  4. Once the plugin has installed click the Activate button.
  5. Access the settings for the plugin - either via the left-hand menu or by clicking the Settings link below the plugins name.
  6. On the General tab scroll down to the Mailer section and select Other SMTP.
  7. You'll see a section appear below titled Other SMTP.
    You'll need to enter the details for the mailbox you'd like to use to send emails.
    SMTP host: will be either mail.yourdomain (replace yourdomain with your domain name e.g. mail.example.co.uk) or your hosting server's name
    Encryption: ideally set to TLS (or SSL)
    SMTP port: 587 (or 465 if using SSL)
    Authentication: On
    SMTP Username: the email address of the mailbox being used to send emails
    SMTP Password: the password of the mailbox being used to send emails
    Click Save Settings to save these details.
  8. Take note of the message about the password being stored in plain text.
    We'd suggest completing the next step of testing that the settings are all working. Then updating your wpconfig.php with these edits and then testing again to make sure everything has stayed working.
  9. Scroll to the top and click the Email Test tab.
    Enter an email address to Send To: and choose whether to send an HTML email or not.
    Click Send Email.
    If all is well you'll see a green success banner and you should receive the email to the address you entered.
    If there are any problems you'll see a red banner detailing the problem. You'll need to fix this before returning here to test again.
  10. Now, edit your wpconfig.php file to include the password - add the following two lines
    define( 'WPMS_ON', true );
    define( 'WPMS_SMTP_PASS', 'your_password' );
    just above the line
    /* That's all, stop editing! Happy publishing. */ 
    Change your_password for your mailbox password.
  11. Once you've added those lines to wpconfig.php you should return to the General tab and remove the SMTP Password and click Save Settings.
    The field will now appear greyed out - but still show the password stars.
  12. Finally switch to the Email Test tab again and send another test email to confirm the details have been added to wpconfig.php correctly.

Any email sent from your WordPress site, including from contact form plugins will now be sent via authenticated SMTP email.

Please remember that your cPanel email accounts are not designed to be used for sending mass emails. Doing so breaches our Acceptable Use Policy. If you want to manage mass mailing lists and send mass emails we'd suggest looking at products like MailChimp, iContact or Constant Contact. These solutions will also enable you to demonstrate compliance with GDPR/privacy rules.


How did we do?


Powered by HelpDocs (opens in a new tab)
© Krystal Hosting Ltd 2002–