Implement PHP mailer with smtp authentication

Implement PHP mailer with smtp authentication

Implement PHP mailer with smtp authentication

This tutorial is for implementing the PHP mailer with SMTP authentication. You can set SMTP authentication mail to your website using this. So simply follow the setup, and you can get working SMTP authentication mail.

Step 1)

Download the PHP mailer library from here. click here for download

Step 2)

Make a function for sending mail as below.

<?php 
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'PHPMailer/src/PHPMailer.php';
require 'PHPMailer/src/SMTP.php';
require 'PHPMailer/src/Exception.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 = "";
$mail->Password = "";
$mail->SMTPSecure = 'tls'; // Enable SSL encryption, TLS also accepted with port 465
$mail->Port = 587; // TCP port to connect to 
$mail->SMTPOptions = array(
    'ssl' => array(
        'verify_peer' => false,
        'verify_peer_name' => false,
        'allow_self_signed' => true
    )
);
//Recipients 
$mail->setFrom('Your SMTP Email Address', 'Your SMTP User Name'); //This is the email your form sends From 
$mail->addAddress('Your User Email Address', 'Your User Name'); // Add a recipient address
//Content 
//$mail->isHTML(true); // Set email format to HTML 
$mail->Subject = 'Your Subject';
$htmldata = "<html>
           <head>
           <title>Title Here</title>
           </head>
           <body>HTML Content</body></html>";
           $mail->IsHTML(true);          
$mail->Body = $htmldata; 
$mail->send(); echo 'Message has been sent'; 
} catch (Exception $e) { echo 'Message could not be sent.'; 
echo 'Mailer Error: ' . $mail->ErrorInfo;
}
?>

Step 3)

Now use the above function to send the SMTP authentication mail via SMTP.

26 responses

26 thoughts on “Implement PHP mailer with smtp authentication

  1. zyban spc

    I’ll immediately grab your rss as I can not to find your e-mail subscription link or e-newsletter service. Do you have any? Kindly permit me recognize so that I may just subscribe. Thanks.

  2. avodart

    I’ll right away clutch your rss as I can not to find your email subscription hyperlink or newsletter service. Do you’ve any? Please let me realize in order that I may just subscribe. Thanks.

  3. domperidone medication

    I simply could not depart your site prior to suggesting that I actually enjoyed the usual info an individual supply on your guests? Is gonna be back steadily in order to investigate cross-check new posts

  4. cenmox

    You made some decent points there. I looked on the web to learn more about the issue and found most people will go along with your views on this site.

  5. back biome

    **back biome**

    Backbiome is a naturally crafted, research-backed daily supplement formulated to gently relieve back tension and soothe sciatic discomfort.

Leave a Reply

Your email address will not be published. Required fields are marked *