$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 1;
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl';
$mail->Host = "smtp.gmail.com";
$mail->Port = 465;
$mail->IsHTML(true);
$mail->Username = "yourname@gmail.com";
$mail->Password = "your_pass";
$mail->SetFrom("your_email");
$mail->Subject = "your_title";
$mail->Body = "your_body";
$mail->AddAddress("receiver_email");
if (!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message has been sent";
}
You have to include phpmailer library. You can download it from here phpmailer
After that you go to your gmail account that you want to use as sender and you need to set 2-step verification ---> off and Allow less secure apps ---> ON.
This guide may help you set up gmail for send emails with php
I am using this script and works fine just make sure to set up all the changes. Maybe you have to add some changes in your xampp ( i did not but i don't know your php.ini file so keep that in mind).