Sent Mail in PHP Using PHPMailer

Kailash Singh

Sent Mail in PHP Using PHPMailer

Published Aug 20,2020 by Kailash Singh

2 Comments     1938 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 = '[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->isHTML(true);
$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";

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