To follow this guide, you need configure msmtp by following our previous guide. After following this guide, WordPress PHP and installation will be able to send you email.
Check Whether PHP Can Send Emails Using mSMTP
We need to test whether the php mail() function is working or not. Create a php script like the one below on your server, edit the required fields and save it as mail.php
Execute this script:
---
1 | php mail.php |
You should be able to receive an email. If you do not receive any email, check our guide How to Easily Set Up Email with SMTP on Ubuntu Server again and your email credentials. Also, check the log at /var/log/msmtp/msmtp.log.

Configure WordPress SMTP Settings to Send Emails Using mSMTP
I have created a small WordPress plugin for you with this content:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | <?php /** * Plugin Name: msmtp mail plugin * Plugin URI: https://thecustomizewindows.com * Description: Helps WordPress to send email using msmtp configuration on server * Author: Abhishek_Ghosh * Author URI: https://thecustomizewindows.com * Version: 1.0 */ /** * This function will connect wp_mail to your authenticated mSMTP server. */ add_action( 'phpmailer_init', 'send_smtp_email' ); function send_smtp_email( $phpmailer ) { if ( ! is_object( $phpmailer ) ) { $phpmailer = (object) $phpmailer; } $phpmailer->Mailer = 'smtp'; $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; } |
You will get the plugin here on my GitHub repository. Simply copy this php file as a new file under /wp-content/plugins/ directory. Name the file as msmtp-mail-plugin.php.
Activate the plugin from WordPress Admin.
Open wp-config.php and add these constants before the line which says “That’s all, stop editing! Happy blogging”:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | // add these before the line which says /* That's all, stop editing! Happy blogging. */ // example with outlook // edit SMTP_HOST, SMTP_USER, SMTP_PASS, SMTP_FROM, SMTP_NAME define( 'SMTP_HOST', 'smtp.office365.com' ); define( 'SMTP_PORT', '587' ); define( 'SMTP_SECURE', 'tls' ); define( 'SMTP_AUTH', true ); define( 'SMTP_USER', 'username@hotmail.com' ); define( 'SMTP_PASS', 'your-password' ); define( 'SMTP_FROM', 'username@hotmail.com' ); define( 'SMTP_NAME', 'microsoft' ); /** Absolute path to the WordPress directory. */ |
Now your WordPress should be able to send email. Restart PHP-FPM. There is a WordPress plugin named Check & Log Email. This plugin will help you to send test email from WordPress.