Send Mail Using PHPMailer From Localhost


PHPMailer is a code library that will help us to send Email from a web server safely and efficiently using PHP Code. A lot of webmasters were using this system to send Email from their web server to the clients. Without having the PHPMailer Class Library, The way of Email Verification system will not be there on the internet. PHPMailer will allow us to send in different ways such as Email with Attachment, Email without Attachment, HTML Email, Simple Text Email, Email with Image, Etc. To implement PHPMailer on a localhost or web server, we need some minimum requirements. Through this article, you are going to learn all the elements and the way of implementation it on localhost and web server.

PHPMailer Live Working Demo:

Download PHPMailer Latest Version from GitHub:

Github is a Script Repository that will help you to download free Opensource project that developed by developers. PHPMailer is also an Opensource script, So you can download it from the GitHub. Follow the below link address to get the latest version of PHPMailer Class file.

Download Composer Dependancy Manager for PHP:

The composer is a Dependancy Manager for PHP. Some PHP Libraries needs the help of some other Libraries to work. In this cases, the Composer Dependancy Manager will help you to get those libraries and work the major library success. PHPMailer also may be consist of some external libraries so you can download them to your PC to work the PHPMailer Class script on your localhost.

Enable extension=php_openssl.dll in php.ini:

Some files in Xampp Localhost server are disabled by commenting them. To work the PHPMailer, you have to enable the extension=php_openssl.dll in php.ini file in your Xampp Folder. The location of the php.ini file given below.
  • C:\xampp\php\php.ini
Open the file using Notepad the find the "extension=php_openssl.dll" then remove the semicolon ";" from the beginning of the code. 

  • Before: ;extension=php_openssl.dll
  • After: extension=php_openssl.dll

Setup an Email for PHPMailer to Send Mail:

The PHPMailer Class file will not send Mail without having a support of any Email services. It is because the mail from a simple PHP code will be considered as Spam in Mail Services like Gmail, Yahoo, Etc. It is better you to create an Email account on Yahoo for PHPMailer because Gmail using high security to protect their client Email. So PHPMailer can't access the functions of Gmail entirely to send mail. So I am strongly recommending you to select Yahoo for creating Mail account for PHPMailer.

Setup PHPMailer for Sending First Email Using Localhost Server:

I hope you did all the things that I explained above. Now you need to do some other steps to make work the PHPMailer script on your localhost.
  1. Move the PHPMailer Libraries to the folder in your htdocs folder inside the Xampp folder.
  2. Extract them if it was a Zip file.
  3. Inside the "PHPMailer-master" you can see an"examples" folder. There you can see different examples of Mailing.
Here on this article, I am not going to use any of that Examples PHP codes to send mail. I customized one of the examples PHP Code myself for text. You can also use the same one that I am using. I shared the script below this paragraph.
require 'mail/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->SMTPAuth = true; 
$mail->Host = "";
$mail->Port = 587; 
$mail->Username = "YOUR YAHOO EMAIL ID"; 
$mail->Password = "YAHOO EMAIL ID PASSWORD"; 
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;
$mail->addReplyTo('REPLAY EMAIL ID HERE', 'First Last');
$mail->addAddress('TO WHOME THE MAIL TO BE SEND', 'John Doe');
$mail->Subject = 'MAIL SUBJECT HERE';
if (!$mail->send()) {
    echo "Mailer Error: " . $mail->ErrorInfo;
} else {
    echo "Message sent!";
  • On the above script, you have to make some changes to work that script correctly such as your Yahoo Email ID, Password, to whom the mail to be send, Your Replay Email ID, Sender Email ID, Etc.
  • Don't forget to change the "require 'mail/PHPMailerAutoload.php';" with the correct path. Otherwise, this example will not work correctly.

How to Solve the Mail Delivery Slow Issue:

Mail services such as Yahoo, Gmail, Microsoft, Etc will take minimum 5 minutes to deliver mail to the client using PHPMailer because of their security issues and server loads. To make it fast, You have to use any privet email services.

Suggested Article for Developers:

I hope you well enjoyed this article. If you have any doubts or suggestions related to this article, Don't hesitate to contact me by using the comment box that given below. Thanks


  1. I just wanna say that you really save my life , you really save me big time :')


Wapmaster or Webmaster can Comment Us with the following Comment Box . Don't add Links to your site for Spamming our Blog .. Once you add Comment with Link . It will be deleted immediatly by our Admins .