PHP Send Email using SMTP Authentication

PHP Send Email using SMTP Authentication

Today, We want to share with you PHP Send Email using SMTP Authentication.
In this post we will show you Send Mail using SMTP in PHP Script, hear for send-e-mail-messages-via-smtp-with-phpmailer-and-gmail we will give you demo and example for implement.
In this post, we will learn about Send Email From a PHP Script Using SMTP Authentication with an example.

Why using GMail(Google) for sending mail messages(SMTP)?

First of all it’s FREE(SMTP Send mail)! Sure most website owners or business site can use their own SMTP server for sending email messages from their website, but it makes sense even than to use GMail(Google Product) for sending mail(SMTP). The chance is big that your websites IP address(reg ip) is on a blacklist(ip) if your site(blog or cms) is on hosted by a shared web hosting provider. If not or you host your blog or site on your own server, there is always a risk that your IP get blacklisted. Because of some limitations send email, the Enabled SMTP server from Google is a future with good choice web applications with less than at least 500 recipients per day, i am sure with check this information from the Google(offical) help pages.

$timezone = "Asia/Kolkata";//initialize timezone using PHP
date_default_timezone_set($timezone); //set Default timezone using PHP
require 'class.phpmailer.php'; //include lib
$to = "[email protected]";

$subject = " services inquiry";
$lname="king of ng";
$bname="Adverts Google Adsense";
$email="[email protected]";
$address="9-ng road,surat.";
$message="Dear ".$fname;

$message .= "



Your First Name is “.$fname.”
User Last Name get is : “.$lname.”
Verify Email address is “.$email.”
Cell Number “.$cellno.”
Current Phone Number is “.$phone.”
Business Name is verify here “.$bname.”
User Address Enabled is “.$address.”

kind Regards,
ng-all SERVICES.

$mail = new PHPMailer;
//init php SMTP mail
// Set mailer to use SMTP
//$mail->SMTPSecure = ‘tls’;
//$mail->SMTPSecure = ‘ssl’;
$mail->Host = ‘’;
// Your web email severe Specify main and backup server
$mail->Port = 465;
// if using ssl->465 and tls->443
// Set the SMTP port
$mail->SMTPDebug = 1;
// Here enables SMTP debug information (for testing)
// 1 = display errors and messages
// 2 = Show messages only
$mail->SMTPAuth = true;
//It’s boolean true or false
// Enable SMTP authentication
$mail->Username = ‘[email protected]’;
// SMTP username
$mail->Password = ‘*********’;
// SMTP password
$mail->SMTPSecure = ‘ssl’;
// there are two type tls and ssl Enable encryption, ‘ssl’ also accepted
$mail->From = ‘[email protected]’;
// from name
$mail->FromName = ‘pakainfo’;

//Maile with attachments Provide file path and name of the attachments
$mail->addAttachment(“yourfile.txt”, “File.txt”); //file.txt
//Filename is optional it’s optional

// Set email format to HTML

$mail->Subject = $subject;//Set subject
$mail->Body = $message; //set mail body

if(!$mail->Send()) {

//echo ‘does not send email with Mailer Error: ‘ . $mail->ErrorInfo;
header(“Location: main_index.html”);

header(“Location: thankyou_page.html”);


Leave a Comment