ONLINE SUPPORT
Online Support Web Hosting

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.

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 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: 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.
    Visit this linked guide to learn how to create a personal email account.

  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:
    <?php
    
    	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 = "sender@yourdomain.com"; // SMTP username
            $mail->Password = "password123"; // SMTP password 
            $Mail->Priority = 1;
    
            $mail->AddAddress("recipient@theirdomain.com","Name");
            $mail->SetFrom("info@yourdomain.com", "Info");
            $mail->AddReplyTo("info@yourdomain.com", "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. 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.

  7. Replace the following values with your own:
  8. 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:

    <?php
          $to      = 'recipient@theirdomain.com';
          $subject = 'Email Test';
          $message = 'Hello World';
          $headers = 'From: sender@yourdomain.com' . "\r\n" .
              'CC: info@theirdomain.com';
              'Reply-To: info@yourdomain.com' . "\r\n" .
              'X-Mailer: PHP/' . phpversion();
    
          mail($to, $subject, $message, $headers);
          echo "Message has been sent.";
          ?>
  9. 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 
  10. 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 "sender@yourdomain.com" 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.

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