Online Support Web Hosting

How to add PHPmailer for Linux and Windows Hosting

What is PHPmailer?

PHPMailer is an open-source library for the scripting language PHP that enables the capability for securely sending email via a web server. This was initially developed by Brent R. Matzelle in 2001 as a project for SourceForge.

The capability of PHPMailer to transport emails comes from the PHP mail() function embedded within its application. PHP mail() function is the actual script that enables the SMTP functionality of PHPMailer.

When you have installed PHPMailer in your site, its code can be found in a .php file.

What can you do with PHPMailer?

With PHPMailer you can do the following tasks in PHP:

  • Send HTML emails
  • Send emails with attachments
  • Send emails via Gmail
  • Send emails using your own SMTP Server
  • Send emails to multiple recipients all at once

How to add PHPMailer for Linux and Windows Hosting

To add PHPMailer to your Linux or Windows Hosting, follow the steps below:

  1. Search for and download PHPMailer. Make sure to get it from a reliable source.
    Important note: In order to use PHPMailer, you will need a domain name and web hosting because you will need to set up a working email account. If you want to test the script, then create two email accounts: a sender and a recipient.

    If you want to know how to create a personal email account, click here.
    After downloading PHPMailer, you will need to access your hosting manager:

  2. Click Sign Up / Log In at the top of this page.

  3. Select Hosting Manager from the drop-down menu.

  4. Enter your username and password. Then, click Log In.

  5. Click on the Files icon, then click the File Manager in the drop-down menu. Choose Web Root (public_html/www). Click Go.

  6. In the next screen, create a new folder. You can name it PHPMailer00 or anything you prefer. Open that new folder.

  7. Inside the new folder, upload the PHPMailer zipped folder you downloaded earlier. Right-click on the zipped folder and extract the files.

  8. Inside the extracted folder, you can get a simple sample script inside the file. Or you can just use the simple sample script below:
    	require 'PHPMailer00/class.phpmailer.php'; // filepath to the PHPMailer class
            require 'PHPMailer00/class.smtp.php';
            $mail = new PHPMailer();
            $mail->SMTPDebug = 2;
            $mail->Mailer = "smtp";
            $mail->Host = "localhost";
            $mail->Port = 587;
            $mail->SMTPAuth = true; // turn on SMTP authentication
            $mail->Username = ""; // SMTP username
            $mail->Password = "password123"; // SMTP password 
            $Mail->Priority = 1;
            $mail->SetFrom("", "Info");
            $mail->AddReplyTo("", "Info");
            $mail->Subject  = "Hello";
            $mail->Body     = "This is my message.";
            $mail->WordWrap = 50;  
            if(!$mail->Send()) {
            echo 'Message was not sent.';
            echo 'Mailer error: ' . $mail->ErrorInfo;
            } else {
            echo 'Message has been sent.';

    Note: Make sure to put closing tags (?>) at the bottom.

  10. Create a new .php file (e.g. test01.php) and save it in the same folder as the extracted PHPMailer folder. Paste the sample script here and then click Save.

  11. Replace the following values with your own:

  12. File path the path of the file that will perform the action or function required for PHPMailer to send emails
    Host your email hosting server
    Username your hosting username
    Password corresponding login password for your hosting
    SetFrom the email address you want the recipient to see as the sender
    AddAddress the email address of the recipient
    AddReplyto the email address you want the recipient to reply to
    Subject the subject of your email
    Body the body or main content of your email

    As an alternative to the PHPMailer script, you can also use the simple PHPmail script below instead:

          $to      = '';
          $subject = 'Email Test';
          $message = 'Hello World';
          $headers = 'From:' . "\r\n" .
              'Reply-To:' . "\r\n" .
              'X-Mailer: PHP/' . phpversion();
          mail($to, $subject, $message, $headers);
          echo "Message has been sent.";

  13. Test if the script works by checking it out on your browser. To do this, put the following url in your address bar:

  14. If everything is in order and the script works, you will see the following message:

      Message has been sent.

Also check your recipient email inbox. If you got an email from "" and it has the message you put in the "body" tag ("This is your message."), then the script works.

Congratulations, you have successfully sent an email via PHPMailer.

Was this helpful? Yes No 61% of people found this helpful.
Need Help?
Talk to one of our dedicated agents now