WordPress sending mail via SMTP without plugins

61 Likes Comment

With the growth of your project, the number of messages sent by the site is growing, and more of them are sent to spam or not reach the recipient at all, because by default WordPress sends messages via standard system traffic.

The way out in this situation is sending letters through SMTP with authorization. And it makes no sense to put plugins, everything is solved in several lines of code in the functions.php file of current theme.

Example for Gmail

add_action('phpmailer_init', function($phpmailer) {
    $phpmailer->isSMTP();
    $phpmailer->Host = 'smtp.gmail.com';
    $phpmailer->SMTPAuth = true;
    $phpmailer->Port = '465';
    $phpmailer->Username = '[email protected]';
    $phpmailer->Password = 'yourpassword';
    $phpmailer->SMTPSecure = 'ssl';
    $phpmailer->From = '[email protected]';
});

Example for Hotmail

add_action('phpmailer_init', function($phpmailer) {
    $phpmailer->isSMTP();
    $phpmailer->Host = 'smtp.gmail.com';
    $phpmailer->SMTPAuth = true;
    $phpmailer->Port = '587';
    $phpmailer->Username = '[email protected]';
    $phpmailer->Password = 'yourpassword';
    $phpmailer->SMTPSecure = 'tls';
    $phpmailer->From = '[email protected]';
});

Example for Zoho

add_action('phpmailer_init', function($phpmailer) {
    $phpmailer->isSMTP();
    $phpmailer->Host = 'smtp.zoho.com';
    $phpmailer->SMTPAuth = true;
    $phpmailer->Port = '587';
    $phpmailer->Username = '[email protected]';
    $phpmailer->Password = 'yourpassword';
    $phpmailer->SMTPSecure = 'tls';
    $phpmailer->From = '[email protected]';
});

Do not forget to replace the values of the variables Username, Password and FromΒ with your data πŸ™‚

You might like

About the Author: Oleksandr Sovenko

Leave a Reply

Your email address will not be published. Required fields are marked *