How to Send Email using SMTP and PHP Mailer

PHPMailer is one of the most popular open source PHP libraries to send emails with attachment. In this tutorial we will tell you how to send email Using SMTP and PHP Mailer. You may also like How to send mail in PHP using PHPMailer and How to send attachment mail in PHP using PHPMailer

Download PHPMailer Library.

$mail = new PHPMailer();
$mail->CharSet = "utf-8";
// enable SMTP authentication
$mail->SMTPAuth = true;
// GMAIL username
$mail->Username = "";
// GMAIL password
$mail->Password = "your_gmail_password";
$mail->SMTPSecure = "ssl";
// sets GMAIL as the SMTP server
$mail->Host = "";
// set the SMTP port for the GMAIL server
$mail->Port = "465";
$mail->From = 'sender email address';
$mail->FromName = 'your website name / your name';
$mail->AddAddress('reciever_email_id', 'reciever_name');
$mail->Subject = 'SMTP Mail Testing';
$mail->Body = 'testing mail';
if ($mail->Send()) {
    echo "Mail Successfully Send";
} else {
    echo "Mail Error - >" . $mail->ErrorInfo;

Leave a Reply

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