PDF download Download Article
Get the PHP application with this easy guide
PDF download Download Article

Need to send emails from your PHP application? The default mailing system in PHP (mail()) doesn't offer the customization features of PHPMailer, which is the most popular mail extension for PHP. This wikiHow will show you how to install PHPMailer using Composer or by adding the extension manually. You need a WAMP or XAMPP environment on Windows to use Composer.

Quick Steps

  1. Download the Composer-Setup.exe file.
  2. Create a "Composer" folder.
  3. Open the Command Prompt.
  4. Go to the directory where you want PHPMailer.
  5. Type "composer require phpmailer/phpmailer" and press Enter.
Method 1
Method 1 of 2:

Using Composer (Windows)

PDF download Download Article
  1. Go to https://getcomposer.org/download/. Composer is a dependency manager for PHP, which means it manages everything your PHP code needs, including libraries and extensions. This is also the easiest method of installing and managing PHPMailer. You'll need to have XAMPP or WAMP installed to use the PHPMailer in a coding environment.
    • You'll find the link to download under the “Windows Installer” header.
  2. Follow the instructions on-screen to install Composer.
    • Choose a PHP executable when prompted to “choose the command-line PHP you want to use.” All executables will end in .exe.
    Advertisement
  3. You'll want to navigate in file browser to the location you will eventually install Composer.
    • Navigate to and double-click the Xampp partition in your file browser, right-click and choose to “Add a New Folder” and name it “Composer.”
  4. You can also access the search window by pressing Win+S. A command-line terminal will load.
  5. For example, type cd C:/xampp/composer.
    • The terminal will confirm it's in that folder.
  6. Terminal will display a wall of text as it installs Composer.
    • For example, you can type the following code in your PHP to include PHPMailer:
      <?php
      
      use PHPMailer\PHPMailer\PHPMailer;
      use PHPMailer\PHPMailer\Exception;
      require 'C:\xampp\composer\vendor\autoload.php';
      
      $email = new PHPMailer(TRUE);
      /* ... */
      
  7. Advertisement
Method 2
Method 2 of 2:

Manually Adding PHPMailer (Windows and macOS)

PDF download Download Article
  1. Go to https://github.com/PHPMailer/PHPMailer. Here you can download the PHPMailer source files directly.
  2. You won't need XAMPP, WAMP, or any other PHP environment.
  3. When you double-click the installed file, you are prompted for the unzipped files location.
    • <?php
      
      use PHPMailer\PHPMailer\PHPMailer;
      use PHPMailer\PHPMailer\Exception;
      
      /* Exception class. */
      require 'C:\PHPMailer\src\Exception.php';
      
      /* The main PHPMailer class. */
      require 'C:\PHPMailer\src\PHPMailer.php';
      
      /* SMTP class, needed if you want to use SMTP. */
      require 'C:\PHPMailer\src\SMTP.php';
      
      $email = new PHPMailer(TRUE);
      /* ... */
      
    • PHPMailer is installed and ready to go on your PHP script.
  4. Advertisement



Expert Q&A

Ask a Question
200 characters left
Include your email address to get a message when this question is answered.
Submit
Advertisement

Tips

Submit a Tip
All tip submissions are carefully reviewed before being published
Name
Please provide your name and last initial
Thanks for submitting a tip for review!

You Might Also Like

Install Laravel Framework in WindowsInstall Laravel Framework in Windows
Install phpMyAdmin on Your Windows PCInstall phpMyAdmin on Your Windows PC
Install XAMPP for Windows Download, Install, and Use XAMPP on Windows
Set up a Personal Web Server with XAMPPSet up a Personal Web Server with XAMPP
Install XAMPP on LinuxInstall XAMPP on Linux
Install WAMPInstall WAMP
Run a PHP File in a Browser Open & Run a PHP File for Beginners
Check PHP Version3 Ways to See Which Version of PHP is Installed + Troubleshooting
Test With PHPTest With PHP
Install the Apache Web Server on a Windows PCInstall the Apache Web Server on a Windows PC
Install Laravel Using LaragonInstall Laravel Using Laragon
Install and Configure Apache Webserver to Host a Website from Your ComputerUse Apache Webserver to Host a Website on Your PC: Step-by-Step
Create a Secure Login Script in PHP and MySQLCreate a Secure Login Script in PHP and MySQL
Start XAMPP at Startup in WindowsStart XAMPP at Startup in Windows
Advertisement

About This Article

Darlene Antonelli, MA
Written by:
wikiHow Technology Writer
This article was co-authored by wikiHow staff writer, Darlene Antonelli, MA. Darlene has been writing and editing tech content at wikiHow since 2019. She previously worked for AppleCare, served as a writing tutor, volunteered in IT at an animal rescue, and taught as an adjunct professor for EN101 and EN102. Darlene has completed Coursera courses on technology, writing, and language. She holds both a BA (2011) and an MA (2012) from Rowan University in Writing, with a focus on workplace communication. With her extensive experience, academic background, and ongoing learning, Darlene has become the go-to grammar expert for her friends and family, as well as a skilled wordsmith for anyone in need. This article has been viewed 115,434 times.
How helpful is this?
Co-authors: 4
Updated: November 28, 2024
Views: 115,434
Categories: PHP
Article SummaryX

1. Download and install Composer from https://getcomposer.org/download/.
2. Click the downloaded file to start the installation process.
3. Create a new Composer folder.
4. Search and open Command Prompt.
5. Navigate to the directory you want to install PHPMailer in.
6. Type composer require phpmailer/phpmailer.
7. PHPMailer is installed in that location.

Did this summary help you?

Thanks to all authors for creating a page that has been read 115,434 times.

Is this article up to date?

Advertisement