Join TalkersCode Now !

Get Latest Tutorials And Links On Web Development
And Get Existing Offers Via Email

Send Email Using SMTP And PHP Mailer

Friday, Apr 7, 2017

Tags:- PHP SMTP Gmail


In this tutorial we will tell you how to send email Using SMTP(Send Mail Transfer protocol) and PHP Mailer.You need to download PHP Mailer library to send Email even from your localhost server using gmail smtp server.


Send Email Using SMTP And PHP Mailer


To Send Email Using SMTP and PHP Mailer it takes only One step:-

  1. Make a PHP file to send Mail


Step 1.Make a PHP file to send Mail

We make a PHP file and save it with a name mail.php

<?php
require_once('phpmail/PHPMailerAutoload.php');
$mail = new PHPMailer();
$mail->CharSet =  "utf-8";
$mail->IsSMTP();
// enable SMTP authentication
$mail->SMTPAuth = true;                  
// GMAIL username
$mail->Username = "your_email_id@gmail.com";
// GMAIL password
$mail->Password = "your_gmail_password";
$mail->SMTPSecure = "ssl";  
// sets GMAIL as the SMTP server
$mail->Host = "smtp.gmail.com";
// set the SMTP port for the GMAIL server
$mail->Port = "465";
$mail->From='your_gmail_id@gmail.com';
$mail->FromName='your_name';
$mail->AddAddress('reciever_email_id', 'reciever_name');
$mail->Subject  =  'SMTP Mail Testing';
$mail->IsHTML(true);
$mail->Body    = 'Hi there , This is just a testing mail';
if($mail->Send())
{
	echo "Message was Successfully Send :)";
}
else
{
	echo "Mail Error - >".$mail->ErrorInfo;
}
?>

In this step first we download the phpmailer library and put all the files in phpmail directory and then insert the main PHPMailerAutoload.php in our document to send mails and that's all now we can send mail and from localhost also but with using internet connection.


Thats all, this is how to Send Email Using SMTP And PHP Mailer Using PHP.You can customize this code further as per your requirement and also you can attach this code to Email Verification On User Signup . And please feel free to give comments on this tutorial.

Join Us With Our 21000+ Subscribers And Get Our Latest Tutorials Update Via Email

Subscribe TalkersCode! One Of The Best
Web Development And Review Blog

Get Latest Tutorials And Reviews
Via Email