Integrate PHPMailer To Use In IIS Without Composer
This post will show you how to add PHPMailer to your IIS PHP configuration without needing to utilize Composer.

In this quick post I will show you how I was able to integrate PHPMailer to send emails with PHP.

My test environment is setup in Windows running IIS.

For my project, I have limited functionality in my production environment. For this reason, I am trying to not utilize Composer in my test environment. My project needed email functionality so I needed to find a way to integrate PHPMailer.

You can manually install the various addons for PHP without the need for Composer by downloading the source and adding it to your project directory. They can be accessed through either require() / include() methods in PHP. There is a drawback for doing this with any library. You may need to require() / include() multiple required files to make the library work.

Integrate PHPMailer In IIS Without Composer 

Source

The post below gives the same simple directions on what you need to do as well as the README file in the project source code located at the root of the project. Look for minimal setup instructions.

https://php-forum.com/index.php?threads/php-mail-and-phpmailer.30517

You need to download the source at

https://github.com/PHPMailer/PHPMailer/releases

Now you can create a simple PHP script to import the needed PHPMailer files and use their functions. In my case I downloaded PHPMailer-6.9.3 and placed it in the root folder of the project for testing.

Code

Below is a sample script created to use PHPMailer. It loads the required assets and builds an email to send. You just need to edit the mail parameters for your own use case.

<?php

require 'PHPMailer-6.9.3/src/PHPMailer.php';
require 'PHPMailer-6.9.3/src/SMTP.php';
require 'PHPMailer-6.9.3/src/Exception.php';

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

$mail = new PHPMailer();
$mail->isSMTP();
$mail->Host = 'mail.servername.com';
$mail->SMTPAuth = true;
$mail->Username = 'username@servername.com';
$mail->Password = 'mypassword';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->setFrom('no-reply@servername.com', 'Admin');
$mail->addAddress('to-address@servername.com', 'Name of Recipient');
$mail->isHTML(true);
$mail->Subject = 'This is the subject';
$mail->Body = '<h3>The body of the email goes here</h3>';

if (!$mail->send()) {
    echo 'Error: ' . $mail->ErrorInfo;
} else {
    echo 'Email sent successfully!';
}

?>

Hope this was useful.