Share this Article !

how to config Microsoft Office 365 mail in wordpress code without using plugin

how to config Microsoft Office 365 mail in wordpress code without using plugin

hello guide, we will show you how to set up Microsoft Office 365 for WordPress email.

first, we need to setup office 365 for sending mails from website and added the code to functions.php and wp-config.php.

we will show you about 2 steps of configuration:

  1. configure in wp-config.php

    // Define constants for SMTP settings
    define( 'SMTP_HOST',     'smtp.office365.com' );
    define( 'SMTP_USER',     'yourusername@gmail.com');
    define( 'SMTP_PASSWORD', 'your_email_password' );
    define( 'SMTP_FROM',     'yourusername@gmail.com' );
    define( 'SMTP_FROMNAME', 'yoursitename' );
    define( 'SMTP_PORT',     '587' );
    define( 'SMTP_AUTH',     true );
    define( 'SMTP_SECURE',   'tls' );

    here is,you define variable and value in wp-config.php

  2. configure in  functions.php
    after define variable and value of parameter,you need call them to functions.php.

    // Use wp-config.php constants in code snippet
    add_action( 'phpmailer_init', 'send_smtp_email' );
    function send_smtp_email( $phpmailer ) {
    $phpmailer->Mailer     = 'smtp';
      $phpmailer->Host =       SMTP_HOST;
      $phpmailer->Username =   SMTP_USER;
      $phpmailer->Password =   SMTP_PASSWORD;
      $phpmailer->From =       SMTP_FROM;
      $phpmailer->FromName =   SMTP_FROMNAME;
      $phpmailer->Port =       SMTP_PORT;
      $phpmailer->SMTPAuth =   SMTP_AUTH;
      $phpmailer->SMTPSecure = SMTP_SECURE;
    }
    add_filter( 'wp_mail_from', function( $email ) {
        return SMTP_FROM;
    } );

This means, “$phpmailer->From = SMTP_FROM;” instead of

“add_filter( ‘wp_mail_from’, function( $email ) { return SMTP_FROM; } );” should use because phpmailer_init may not overwrite from information.

if you don’t include or add_filter(), I think may not work.

Finally,I hope this article help you.

Share this Article !


You may like this
Top 10 most popular programming language in 2025

Top 10 most popular programming language in 2025

Nowadays, we know and see coding skills hold immense value in technology beyond 1990 till 2025, with effects on career advancement being profound. Extremely popular languages such as Python, JavaScript, and Java...
how to improve seo and increase audience for your website

how to improve seo and increase audience for your website

To increase your audience and boost your SEO (Search Engine Optimization), you’ll need to implement a mix of technical strategies, content creation, and marketing campaigns. This is a step-by-step guide to help...
Moodle – how get total course completed and login chart in current year into dashboard page

Moodle – how get total course completed and login chart in current year into dashboard page

To add the total course completed and login chart in the current year to the dashboard, you need to get a query from course complete and login from the database. We created...
(100% worked) How to fix PHP is not recognized as an internal or external command for Xampp Or Wamp

(100% worked) How to fix PHP is not recognized as an internal or external command for Xampp Or Wamp

5 steps for fixing PHP is not recognized as an internal or external command for Xampp rr Wamp. You can follow the tips below. Go to My Computer->properties -> Advanced system setting->...
How to loop post under category in wordpress

How to loop post under category in wordpress

To loop posts under categories, you should know something. get_categories($args): Arguments to retrieve categories and we want to return array List of category objects that   ‘parent’ => 0 .  $categories =...
boostrap columns left in desktop and right in mobile

boostrap columns left in desktop and right in mobile

When you want to change columns left on desktop and right on mobile, we always think about the responsive screen.This tip will help you. following the below code : <div class="container">  ...