Knowledge Base

How to Add PHPMailer for Linux and Windows Hosting

PHPMailer is an open-source library for the scripting language PHP that enables the capability for securely sending email via a web server. If you want to add PHPMailer either you are using a Linux or Windows hosting you can do so via your File Manager. Read through this article to learn how to do it.

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.
  2. Access your File Manager.
  3. Scroll to public_html folder and locate your php.ini file.
  4. Inside the public_html folder, create a new folder. Name the new folder, for example, PHPMailer00. Then, open the new folder.
  5. Extract the downloaded PHPMailer zipped file.
  6. Add the necessary classes in your PHP script. 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 = "[email protected]"; // SMTP username
            $mail->Password = "password123"; // SMTP password 
            $Mail->Priority = 1;
            $mail->AddAddress("[email protected]","Name");
            $mail->SetFrom("[email protected]", "Info");
            $mail->AddReplyTo("[email protected]", "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.';
  7. Replace the following values with your own:
    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      = '[email protected]';
          $subject = 'Email Test';
          $message = 'Hello World';
          $headers = 'From: [email protected]' . "\r\n" .
              'CC: [email protected]';
              'Reply-To: [email protected]' . "\r\n" .
              'X-Mailer: PHP/' . phpversion();
          mail($to, $subject, $message, $headers);
          echo "Message has been sent.";
  8. Test if the script works by checking it out on your browser. To do this, put the following url in your address bar:
    yourdomainname.com/folder name/filename.php 
  9. 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 "[email protected]" and it has the message you put in the "body" tag ("This is your message."), then the script works.

Well done! You’ve successfully added PHPMailer and completed this guide. Please contact us know if you need any further assistance in setting up your PHPMailer, or if you have any questions.

Did you find this article helpful?

* Your feedback is too short