WordPress SMTP settings without using plugin

Using a default function wp_mail() is not ideal. Many emails will end up in spam folder. And you want email in standard inbox, right? Ideal situation is when your WordPress web site will be sending emails over SMTP settings.

Here is a working solution how to set WordPress SMTP settings without using third-party plugin. We will use this two code snippets.

Place this code snippet into your wp-config.php file above ‘Happy blogging’ line. Keep in mind you will use your own settings.

// SMTP Authentication for wp-config.php
define('SMTP_USER', 'user@example.com'); // Username for SMTP authentication
define('SMTP_PASS', 'smtp password'); // Password  for SMTP authentication
define('SMTP_HOST', 'smtp.example.com'); // Hostname, mail server
define('SMTP_FROM', 'website@example.com'); // SMTP From email address,
define('SMTP_NAME', 'e.g Website Name'); // From name, eg Jon Doe
define('SMTP_PORT', '465'); // SMTP port 465 or 587, don't use unencrypted 25
define('SMTP_SECURE', 'tls'); // set ssl or tls
define('SMTP_AUTH', true); // Using SMTP authentication
define('SMTP_DEBUG', 0); // debugging, options 1 or 2

Now this second code snippet for SMTP is for WordPress theme file function.php. Just paste it as it is.

// SMTP Authentication for function.php
add_action('phpmailer_init', 'send_smtp_email');
function send_smtp_email($phpmailer) {
$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; }

Yes, little bit extra work around. but now we can be happy we set up SMTP without plugin in WordPress. It’s good to know it! And chceck with your mail provider you have active DKIM.

DKIM stands for Domain Keys Identified Mail. It is an authentication that allows the receiver to check that an email was indeed send and authorized by the domain owner.