SMTP Settings of Wordpress - Without Using Plugin

dailydose
#1

Let’s learn how to configure SMTP for your WordPress without using any plugin.

  1. Add following code to your wp-config.php file (above ‘’ Happy blogging ‘’ field ) and edit it according to smtp authentication of your mail:
    // SMTP Authentication
    define( 'SMTP_USER',   'user@example.com' );    // Username to use for SMTP authentication
    define( 'SMTP_PASS',   'smtp password' );       // Password to use for SMTP authentication
    define( 'SMTP_HOST',   'smtp.example.com' );    // The hostname of the mail server
    define( 'SMTP_FROM',   'website@example.com' ); // SMTP From email address
    define( 'SMTP_NAME',   'e.g Website Name' );    // SMTP From name
    define( 'SMTP_PORT',   '25' );                  // SMTP port number - likely to be 25, 465 or 587
    define( 'SMTP_SECURE', 'tls' );                 // Encryption system to use - ssl or tls
    define( 'SMTP_AUTH',    true );                 // Use SMTP authentication (true|false)
    define( 'SMTP_DEBUG',   0 );                    // for debugging purposes only set to 1 or 2
  1. Add following code to functions.php of your theme or using Code Snippet plugin.
    // SMTP Authentication
    add_action( 'phpmailer_init', 'send_smtp_email' );
    function send_smtp_email( $phpmailer ) {
    	$phpmailer->isSMTP();
    	$phpmailer->Host       = SMTP_HOST;
    	$phpmailer->SMTPAuth   = SMTP_AUTH;
    	$phpmailer->Port       = SMTP_PORT;
    	$phpmailer->Username   = SMTP_USER;
    	$phpmailer->Password   = SMTP_PASS;
    	$phpmailer->SMTPSecure = SMTP_SECURE;
    	$phpmailer->From       = SMTP_FROM;
    	$phpmailer->FromName   = SMTP_NAME;
    }

NOTE: Ensure that, your wp-config.php file is not accessible. Because this keeps it away from prying eyes.

Protect wp-config.php file

To keep your wp-config.php secure, add following code to your .htaccess:

<files wp-config.php>
order allow,deny
deny from all
</files>

Or, if you still want plugin method check How to Fix the WordPress Not Sending Emails Issue

I hope this helps.

3 Likes

How to Fix the WordPress Not Sending Emails Issue
Is your WordPress really able to send e-mail to your user?
Best G Suite Reseller in India
#2

Once again, I’d like to Question the obvious advantage of hosting an email server locally vs using a 3rd party email provider?

0 Likes

#3

It doesn’t matter. You can use this in both situations. You don’t need to use ‘’ Easy SMTP ‘’ plugin or someting else.

For your question, I’m using shared hosting for my Wordpress site. Mail service of shared hosting is not efficient. And also it is so limited. Most of e-mail providers are seeing my mails as a spam.

If you have high traffic, contact form, and comment reply notifications plugin or something else related to sending e-mail to your visitors in your wordpress, You will need to use 3rd party e-mail provider in this situation.

Yandex mail is quite good about fixing this issues. It provides security, higher limit, anti-spam features, and etc…

1 Like

#4

I use mailgun to programmatically deliver all the emails using their API. As we’re using multisite, it needs it’s config in the wp-config file but I can put my bets on mailgun offering a better delivery rate than self hosted SMTP.

0 Likes

#5

I never tried mailgun. It looks like a good service.
However, I think mail subscription system on blogs is dying. There are alternatives better than mailing lists.
For example, OneSignal or Telegram channel to publish your last posts for sending notification to visitors.

0 Likes

#6

Telegram is better. People get annoyed of obnoxious notifications triggered for no reason. I personally use telegram bot to publish updates to a muted group and read it at night just like old fashioned RSS feed.

1 Like

#7

I agree with you brother! Telegram has reached 100 million active users And also growing fast.
Bot-Father provides you whatever you want as a developer.

1 Like

#8

Sending e-mail straight to inbox can help in improving communication with visitors.

If your WordPress e-mail is landing to spam folder, I would suggest trying above approach with a transnational e-mail services provider like AWS SES. It works great!

Thanks @turk for sharing this guide.

1 Like

#9

Thank you for this.

Would you please explain how it could work with Multi-Site?
Because different sites, would often use different “Send From” emails or even completely different smtp creds… Id like to figure out how to do it on MS…

Thanks!

0 Likes