Sent Mail in PHP Using PHPMailer

Kailash Singh

Sent Mail in PHP Using PHPMailer

Published Aug 20,2020 by Kailash Singh

2 Comments     1776 Views    

In this tutorial, we are going to learn about how to sent mail using PHP Mailer in PHP.


PHPMailer is perhaps the most popular open-source PHP library to send emails with.


Step 1 :- You need to use PHP Mailer Library


Click here to get PHP Mailer Library


Step 2 :- Create index file (index.php).



require('PHPMailer/phpmailer/PHPMailerAutoload.php'); // Here i am providing PHP Mailer Library path
$mail = new PHPMailer();

$mail->Host = '';
$mail->Port = '587';
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'tls';

$mail->Username = '[email protected]'; // Add Gmail ID Here
$mail->Password = '123456'; // Add Gmail Password Here

$mail->setFrom('[email protected]','This is testing'); // Here add your Email ID & Subject
$mail->addAddress('[email protected]');  // Here add User Email ID
$mail->addReplyTo('[email protected]'); // Here add your Email ID. Where user can send email

$mail->Subject = 'This is only testing'; // This is subject of Email

$name = "Kailash";
$phone = '7017277899';
$email = '[email protected]';

$msg = "Name: $name";
$msg .= "<br>";
$msg .= "Mobile: $phone";
$msg .= "<br>";

$mail->Body = "$msg";

	echo "Message could not be sent!";
	echo "Message could be sent!";






Hope this will help our developers.


Ankesh sharma Oct 18, 2020

Thank you so much for help

Elevenstech Oct 23, 2020