How to use PHPMailer


Hello everybody!

I know most of you send out emails via PHP using the built in mail() function.
But, did you know that PHPMailer exists?

Never fail sending any email.
How? PHPMailer.

Let’s dive right into the tutorial…


Install the PHPMailer files from this github repo





Upload it to your website and extract it


Login to the file manager at


Drag and drop the ZIP onto the file manager then hit the Upload button


Hit on the ZIP file once, then right click and hit Extract

Define . as your location to extract the ZIP in the current directory

And hit Extract

After that,

Rename the extracted folder to mail

Now, let’s setup

Enter the mail>src directory, then move all the files back to the mail directory


Now go back to the mail directory, and delete everything Selected in the image below

The script is now ready

To be used in a PHP file!


Enable less secure apps in Gmail


Copy and paste this code onto the file which should send the email

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

require $_SERVER['DOCUMENT_ROOT'] . '/mail/Exception.php';
require $_SERVER['DOCUMENT_ROOT'] . '/mail/PHPMailer.php';
require $_SERVER['DOCUMENT_ROOT'] . '/mail/SMTP.php';

$mail = new PHPMailer;
$mail->SMTPDebug = 2; // 0 = off (for production use) - 1 = client messages - 2 = client and server messages
$mail->Host = ""; // use $mail->Host = gethostbyname(''); // if your network does not support SMTP over IPv6
$mail->Port = 587; // TLS only
$mail->SMTPSecure = 'tls'; // ssl is deprecated
$mail->SMTPAuth = true;
$mail->Username = ''; // email
$mail->Password = 'PASSWORD'; // password
$mail->setFrom('', 'CKSoftwares System'); // From email and name
$mail->addAddress('', 'Mr. Brown'); // to email and name
$mail->Subject = 'PHPMailer GMail SMTP test';
$mail->msgHTML("test body"); //$mail->msgHTML(file_get_contents('contents.html'), __DIR__); //Read an HTML message body from an external file, convert referenced images to embedded,
$mail->AltBody = 'HTML messaging not supported'; // If html emails is not supported by the receiver, show this body
// $mail->addAttachment('images/phpmailer_mini.png'); //Attach an image file

    echo "Mailer Error: " . $mail->ErrorInfo;
    echo "Message sent!";

Change the lines which have comments next to them according to your needs.

And enable IMAP in your gmail settings

Then complete this

And finally, enjoy!

Mail from my site don't works
SMTP Server and password

If you encounter any issues, report them here