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.
Thank you a bunch for sharing this with all people you really understand what you are speaking about! Bookmarked. Please also consult with my site =). We will have a hyperlink change agreement among us
I am sure this article has touched all the internet users, its really really good article on building up new webpage.
Well I truly liked studying it. This article procured by you is very practical for accurate planning.
I am sure this piece of writing has touched all the internet visitors, its really really fastidious paragraph on building up new weblog.
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.
I am sure this article has touched all the internet people, its really really good article on building up new blog.
I am sure this piece of writing has touched all the internet visitors, its really really pleasant post on building up new web site.
I’ll immediately seize your rss as I can not in finding your email subscription hyperlink or newsletter service. Do you’ve any? Please permit me realize in order that I could subscribe. Thanks.
Very quickly this web page will be famous amid all blog users, due to it’s fastidious posts
Thanks for finally writing about >Cognitive Treatment For Depression And Anxiety – Canadian RX Meds Blog <Loved it!
I am not rattling superb with English but I get hold this very leisurely to translate.
I will right away seize your rss as I can not find your email subscription link or e-newsletter service. Do you have any? Kindly permit me realize in order that I may subscribe. Thanks.