PHP Add PHPMailer To Use In IIS Without Composer

You are currently viewing PHP Add PHPMailer To Use In IIS Without Composer

In this quick post I will show you how I was able to integrate basic PHPMailer functionality to send emails with PHP in Windows running IIS without needing Composer.

For my setup, I am trying to not utilize Composer in my test environment due to the potential limitations in my production environment. For this reason, I needed to find a way to install PHPMailer.

You can simply 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.

Code

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

Basically 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 function. In my case I downloaded PHPMailer-6.9.3 and placed it in the root folder of the project for testing.

<?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!';
}

?>

Leave a Reply