Sent Mail in PHP Using PHPMailer

Kailash Singh
Sent Mail in PHP Using PHPMailer
Published Aug 20,2020 by Kailash Singh

2 Comments     421 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).

 

<?php

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

$mail->Host = 'smtp.gmail.com';
$mail->Port = '587';
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'tls';

$mail->Username = '123@gmail.com'; // Add Gmail ID Here
$mail->Password = '123456'; // Add Gmail Password Here

$mail->setFrom('elevenstech@gmail.com','This is testing'); // Here add your Email ID & Subject
$mail->addAddress('ks623039@gmail.com');  // Here add User Email ID
$mail->addReplyTo('elevenstech@gmail.com'); // Here add your Email ID. Where user can send email

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

$name = "Kailash";
$phone = '7017277899';
$email = '123@gmail.com';

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

$mail->Body = "$msg";

if(!$mail->send())
{
	echo "Message could not be sent!";
}
else{
	echo "Message could be sent!";
}


?>

 

Result: 

 

 

Hope this will help our developers.

2 Comments


Ankesh sharma Oct 18, 2020

Thank you so much for help

Elevenstech Oct 23, 2020

welcome