Send mail through WordPress (without using SMTP plugins)

WordPress itself does not provides SMTP settings to configure in the admin area.

But there are two ways that you can send mail from WordPress:

  1. By using plugins that set up SMTP connections to outside mail servers.
  2. Or by using WordPress’ internal wp_mail() function, which defaults to using PHP’s mail() function, fully relying on PHP’s settings to handle mail.

To send mail via wp_mail(), WordPress uses an internal PHPMailer class which sets some default values.

The included PHPMailer class defaults to using PHP’s mail() function, but can also instead connect to your mail account (e.g., gmail) directly.

To use the mail() function, you’ll need to enable and configure MSMTP to establish a local SMTP proxy/forwarding to a real mail server or mail account (such as gmail).

Then edit file –
wp-includes\class-phpmailer.php

Change…

public $From = 'root@localhost';
public $Host = 'localhost';
public $SMTPAutoTLS = true;

To…

public $From = 'name@gmail.com';
public $Host = '127.0.0.1';
public $SMTPAutoTLS = false;

The above settings is for a local SMTP proxy such as MSMTP or for a local SMTP server.

If you want to connect to gmail directly, change “$Mailer” to “SMTP” and update settings accordingly.

Debugging SMTP Issues

Check the website’s HTTP and PHP error log files, and the general PHP error log file for logged PHP errors.

Check PHP’s mail() function log and MSMTP’s log file to make sure that email is not being rejected because the header/from is invalid.

PHP mail log – C:\WampDeveloper\Logs\Php\maillog.txt

MSMTP mail log – C:\WampDeveloper\Tools\msmtp\msmtplog.txt

3 thoughts on “Send mail through WordPress (without using SMTP plugins)”

  1. hi, i am using wamp and tried to use msmtp to send automated wordpress registration email(the password and verification link) from first gmail to second gmail and failed. My registration plugin is using wp_new_user_notification method. I’ve tested msmtp with php file and it worked perfectly; (The email received by second gmail is inside first gmail sent folder) but not for the wordpress automated mail. I’ve change “$Mailer” to “SMTP” and inserted all the smtp info and failed. How should i configure the class-phpmailer.php to make this work? Do i need type in all the smtp infor again to the wordpress writing setting in dashboard? thanks in advance.

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>