How to install PHPMailer in shared hosting

PHPMailer — Installing on a Shared server


PHPMailer allows you to send email from your site via SMTP. Visit PHPMailer’s GitHub page for further details on what it has to offer.

This article explains how to install PHPMailer on a Shared server. If your website is on a VPS or Dedicated server, view the following article instead.

  • Installing PHPMailer on a VPS or Dedicated server

Installing PHPMailer

  1. Log into your server via SSH.
  2. Make sure you're in your user's home directory.
[server]$ cd ~​

 3. Download the zip file from

[server]$ wget

4. Unzip the file. 

[server]$ unzip

This creates a directory named 'PHPMailer-master'.

5. Rename this directory.

[server]$ mv PHPMailer-master PHPMailer

Basic code example for email hosted at Da-Manager

Insert the following code into a PHP file.

You only need to update the code in bold.

username — Make sure to change the 'username' field to your actual shell username. You can also view this by running the following command.

[server]$ echo $USER

Host — If you're sending from a Da-Manage raddress, you should only use If you are using a Gmail address, use

Username and setFrom must both be an email on the domain you're sending from.

// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

require '/home/username/PHPMailer/src/Exception.php';
require '/home/username/PHPMailer/src/PHPMailer.php';
require '/home/username/PHPMailer/src/SMTP.php';

$mail = new PHPMailer(true);                              // Passing `true` enables exceptions
try {
    //Server settings
    $mail->SMTPDebug = 2;                                 // Enable verbose debug output
    $mail->isSMTP();                                      // Set mailer to use SMTP
    $mail->Host = '';                   // Specify main and backup SMTP servers
    $mail->SMTPAuth = true;                               // Enable SMTP authentication
    $mail->Username = '';              // SMTP username
    $mail->Password = 'secret';                           // SMTP password
    $mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
    $mail->Port = 587;                                    // TCP port to connect to

    $mail->setFrom('', 'Mailer');          //This is the email your form sends From
    $mail->addAddress('', 'Joe User'); // Add a recipient address
    //$mail->addAddress('');               // Name is optional
    //$mail->addReplyTo('', 'Information');

    //$mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
    //$mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name

    $mail->isHTML(true);                                  // Set email format to HTML
    $mail->Subject = 'Subject line goes here';
    $mail->Body    = 'Body text goes here';
    //$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

    echo 'Message has been sent';
} catch (Exception $e) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;


Was this answer helpful? 0 Users Found This Useful (0 Votes)

Powered by WHMCompleteSolution