Send SMTP E-Mail Using PHPMailer

PHPMailer is the most popular code for sending email from PHP. It involves simple integration technique to send a email.

Key Features :

  • Integrated SMTP support
  • Compatible with PHP 5.0 and later
  • Multipart/alternative emails for mail clients that do not read HTML email
  • Support for UTF-8 content and 8bit, base64, binary, and quoted-printable encoding

Example to send a SMTP email:

Download the package form phpmailer GitHub,  Extract the zip format file and find the below php files in it.

  1. class.phpmailer.php
  2. class.smtp.php
  3. class.pop3.php
require 'class.phpmailer.php';
require 'class.smtp.php';
require 'class.pop3.php';

$mail = new PHPMailer;

//$mail->SMTPDebug = 3;   // Enable verbose debug output

$mail->Host = '';  
$mail->SMTPAuth = true;                               
$mail->Username = ''; // SMTP username
$mail->Password = 'secure';  // SMTP password
$mail->SMTPSecure = 'ssl'; // Accept SSL/TLS 
$mail->Port = 465;  // TCP port to connect to

$mail->From = '';
$mail->FromName = 'Padmanaban Mailer';
$mail->addReplyTo('', 'Information');

$mail->isHTML(true); // Set email format to HTML

$mail->Subject = 'Here is the subject';
$mail->Body    = 'This is the HTML message body <b>in bold!</b>';

if(!$mail->send()) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
    echo 'Message has been sent';

Download File