The Steps To Send Mail From Localhost XAMPP Using Gmail:

Step 1:

Download PHPMailer Zip File from this link: https://github.com/PHPMailer/PHPMailer

setp1.jpg

Step 2:

Extract Zip file to htdocs/foldername in which you want to write code for Email.

Step 3:

Now create a new PHP file in this[Email] folder with any name [ex:phpmailer.php I have given this name]

Step 4:

        Now write the code to use two library files in your php page.

        use PHPMailer\PHPMailer\PHPMailer;

use PHPMailer\PHPMailer\Exception;

Step 5:

        Now write the code to include three php pages into your page.

        [Write the proper path of those files.]

require 'PHPMailer/src/Exception.php';

require 'PHPMailer/src/PHPMailer.php';

require 'PHPMailer/src/SMTP.php';

Step 6:

After the above code then write these lines of codes and do some necessary changes.

$mail = new PHPMailer(true);

try {

$mail->isSMTP();   //Send using SMTP

    $mail->Host = 'smtp.gmail.com';                     //Set the SMTP server to send through

$mail->SMTPAuth = true;                           //Enable SMTP authentication

$mail->Username= 'youremail_id@rku.ac.in';                     //SMTP username

$mail->Password= 'yourpassword';    //SMTP password

$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;           //Enable implicit TLS encryption

$mail->Port= 465;

//TCP port to connect to; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS`;

//Recipients

$mail->setFrom('youremail_id@rku.ac.in','Jay Fuletra'); // Your name to display

$mail->addAddress('email_id'); //Add a recipient

//$mail->addAddress('ellen@example.com');           //Name is optional

//$mail->addReplyTo('info@example.com', 'Information');

//$mail->addCC('cc@example.com');

//$mail->addBCC('bcc@example.com');

//Attachments

//$mail->addAttachment('/var/tmp/file.tar.gz');      //Add attachments

//$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); //Optional name

//Content

$mail->isHTML(true);  //Set email format to HTML

$mail->Subject = 'Testing Mail sending using xampp';

$mail->Body    = 'Hey there I am trying to send mail from localhost using xampp server';

$mail->send();

echo 'Message has been sent';

}

catch (Exception $e) {

echo "Message could not be sent. Mailer Error:

{$mail->ErrorInfo}";

}

?>

Step 7:

Open your Gmail Account and go to manage your Google Account.

Step 8:

Find the security tab from the left panel and go to less secure app access and switch it on.