A Web.com Partner
Sign Up / Log In
Online Support Windows Hosting

How To Add PHPMailer for Windows Hosting in Plesk

PHPMailer is an open-source library for the PHP scripting language that enables the capability for securely sending email via a web server.

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. In this guide, we'll help you better understand what you can do after adding PHPMailer, and learn how to add PHPMailer via Ples.

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

Note: Our mail server is not an open relay, which means that authorization is always needed in PHPMailer config.

How To Add PHPMailer for Windows Hosting in Plesk

You will need to first, 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, which you will be using 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 in Plesk, click here.

After downloading, you can add PHPMailer for your Windows Hosting in Plesk by following the instructions below:

  1. Access your Hosting Manager.
  2. Click Files from the left-side menu.
  3. Under File Manager, click on the httpdocs folder to open it.
  4. Within the httpdocs folder, click on the + New button at the top and select Create Directory to create a new folder.
  5. You can name it PHPMailer00 or anything you prefer, then click OK.
  6. Open that new folder by clicking on it.
  7. Inside the new folder, click on the Upload button at the top to upload the PHPMailer zipped folder you downloaded earlier.
  8. Right-click on the zipped folder and extract the files.
  9. Click on the extracted folder to open it. You can get a simple sample script inside the README.md file.
    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 include the closing tags (?>) at the bottom.

  10. Click on the + New button at the top and select Create File to create a new .php file (e.g. test01.php), then click OK to save it in the same folder as the extracted PHPMailer folder.
  11. Click on the new file to open it then paste the sample script here.
  12. Replace the following values with your own and click OK to save:
    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 The 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.";
        ?>
  13. 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
        
  14. If everything is in order and the script works, you will see the following message:
    
        Message has been sent.
        

Note: 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.

You have successfully added PHPMailer for Windows Hosting in Plesk. If you have questions, or if you need any asssitance in adding PHPMailer to your Windows Hosting, please let us know. We'd love to help!

Was this helpful? Yes No 69% of people found this helpful.
{"message":""}