All TalkersCode Topics

Follow TalkersCode On Social Media

devloprr.com - A Social Media Network for developers Join Now ➔

Send Email Using SMTP And PHP Mailer

Last Updated : Jul 1, 2023

IN - PHP SMTP Gmail | Written & Updated By - Dikshita

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.

I hope this tutorial on send email using php helps you and the steps and method mentioned above are easy to follow and implement.