setup outlook smtp - wordpress guru

Outlook SMTP Setup with PHPMailer: Easy Email Sending

In today’s tutorial, we’re diving into programmatically sending emails. We’ll explore how you can use PHPMailer, a popular PHP library, for Outlook SMTP Setup with PHPMailer to send emails using Outlook’s SMTP service. If you’ve ever needed to integrate email functionality into your PHP application, you’re in the right place!

Getting Started with Outlook SMTP Setup with PHPMailer

Step 1: Install or Download PHPMailer

First, let’s get PHPMailer set up and configure it to work with Outlook’s SMTP service. You can use Composer, PHP’s package manager, to install PHPMailer. If you haven’t already, make sure you have Composer installed and ready to go.

composer require phpmailer/phpmailer

Alternatively, if you’re not using Composer, you can download PHPMailer as a zip file from GitHub, then copy the contents of the PHPMailer folder into one of the include_path directories specified in your PHP configuration and load each class file manually:

First, you need to download PHPMailer 5.2 stable version from GitHub

stable-php-mailer-5.2

afterword download the PHPMailder zip file from the right side by clicking on the green code button.

download-phpmailer-zip-file

After downloading extract the zip file and rename the folder to PHPMailer.

extract phpmailer 5.2 zip file

rename it to PHPMailer

Now Make a zip file after renaming the folder to PHPMailer

make a zip file

upload that zip file to your server folder from where you want to send the email using that PHPMailer library.

upload phpmailer to your server

after uploading the zip file to the server extract it and place it in the root folder or other directory according to your need.

extract uploaded PHPMailer zip file in server

Now create a PHP file in your server where you extracted the PHPMailer Folder.

create-new-php-file-for-sending-email

after creating a new PHP file edit it and add a sample code to the file. check the sample code below the screenshot.

open new php file and put sample code in

A Simple Example

[PHP]

<?php
require 'PHPMailerAutoload.php';

$mail = new PHPMailer;

//$mail->SMTPDebug = 3;              // Enable verbose debug output

$mail->isSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'smtp1.example.com;smtp2.example.com';  // Specify main and backup SMTP servers
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = 'user@example.com';                 // SMTP username
$mail->Password = 'secret';                           // SMTP password
$mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587;                                    // TCP port to connect to

$mail->setFrom('from@example.com', 'Mailer');
$mail->addAddress('joe@example.net', 'Joe User');     // Add a recipient
$mail->addAddress('ellen@example.com');               // Name is optional
$mail->addReplyTo('info@example.com', 'Information');
$mail->addCC('cc@example.com');
$mail->addBCC('bcc@example.com');

$mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
$mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name
$mail->isHTML(true);                                  // Set email format to HTML

$mail->Subject = 'Here is the subject';
$mail->Body    = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

if(!$mail->send()) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
    echo 'Message has been sent';
}
?>

[/php]

2: Find SMTP Setting

Now you need to log in to your Outlook email and find the Outlook SMTP setting for PHPMailer.

outlook email smtp setting

Copy all Outlook SMTP details into your mail.php file that we created earlier, server name, port, and encryption method.

Step 3: Enable SMTP AUTH for specific mailboxes

Use the Microsoft 365 admin center to enable or disable SMTP AUTH on specific mailboxes

  1. Open the Microsoft 365 admin center and go to Users > Active users.
  2. Select the user, and in the flyout that appears, select Mail.
  3. In the Email apps section, select Manage email apps.
  4. Verify the Authenticated SMTP setting: unchecked = disabled, checked = enabled.
  5. When you’re finished, select Save changes.

outlook active user

manage email app

make sure the authenticated SMTP box checked

check authenticated auth

Step4: Update your sample code with Outlook SMTP setup with PHPMailer details

Your Outlook email, and password (The password should be the same as that you use for login to the webmail server)

</p><pre>&lt;?php
require 'PHPMailer/PHPMailerAutoload.php';

$mail = new PHPMailer;

//$mail-&gt;SMTPDebug = 3;              // Enable verbose debug output

$mail-&gt;isSMTP();                                      // Set mailer to use SMTP
$mail-&gt;Host = 'smtp.office365.com';  // Specify main and backup SMTP servers
$mail-&gt;SMTPAuth = true;                               // Enable SMTP authentication
$mail-&gt;Username = 'user@example.com';                 // SMTP username
$mail-&gt;Password = 'secret';                           // SMTP password
$mail-&gt;SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
$mail-&gt;Port = 587;                                    // TCP port to connect to

$mail-&gt;setFrom('from@example.com', 'Mailer');
$mail-&gt;addAddress('joe@example.net', 'Joe User');     // Add a recipient
//$mail-&gt;addAddress('ellen@example.com');               // Name is optional
$mail-&gt;addReplyTo('info@example.com', 'Information');
//$mail-&gt;addCC('cc@example.com');
//$mail-&gt;addBCC('bcc@example.com');

//$mail-&gt;addAttachment('/var/tmp/file.tar.gz');         // Add attachments
//$mail-&gt;addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name
$mail-&gt;isHTML(true);                                  // Set email format to HTML

$mail-&gt;Subject = 'Here is the subject';
$mail-&gt;Body    = 'This is the HTML message body &lt;b&gt;in bold!&lt;/b&gt;';
$mail-&gt;AltBody = 'This is the body in plain text for non-HTML mail clients';

if(!$mail-&gt;send()) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail-&gt;ErrorInfo;
} else {
    echo 'Message has been sent';
}
?&gt;</pre><p>

After adding all the necessary details in your mail.php file try to hit the url in the web browser for example, https:mywebsite.com/mail.php, and you will see that the PHP script will send the email to your recipient address.

mail sent to gmail

And there you go! By following these steps, you should now be able to seamlessly integrate Outlook SMTP setup with PHPMailer, allowing you to send out emails from your custom PHP forms or applications.

If you need any help regarding SMTP setup, please contact me. You can also get a free quote by submitting the form in the top right sidebar. Happy coding!

Leave a Comment

×

Hello!

Click on the contact below to start a chat with us on WhatsApp.

× Need Help?