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. The PHP mail() function is the actual script that enables the SMTP functionality of PHPMailer.
When you have installed PHPMailer on 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 Plesk.
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:
- Access your Hosting Manager.
- Click Files from the left-side menu.
- Under File Manager, click on the httpdocs folder to open it.
- Within the httpdocs folder, click on the + New button at the top and select Create Directory to create a new folder.
- You can name it PHPMailer00 or anything you prefer, then click OK.
- Open that new folder by clicking on it.
- Inside the new folder, click on the Upload button at the top to upload the PHPMailer zipped folder you downloaded earlier.
- Right-click on the zipped folder and extract the files.
- 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 = "[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.'; } ?>
NOTE: Make sure to include the closing tags (?>) at the bottom.
- 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.
- Click on the new file to open it then paste the sample script here.
- 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 = '[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."; ?>
- Test if the script works by checking it out in your browser. To do this, put the following URL in your address bar:
yourdomainname.com/folder name/filename.php
- 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 "[email protected]" 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 assistance in adding PHPMailer to your Windows Hosting, please let us know. We'd love to help!