ive been trying to send email via gmail the last couple days for my project. Attempting to build a password reset system with xampp and phpmailer for gmail. Within my data base the sql request is identified but sending off the email is where i am stuck.
<?php
include 'databaseconnection.php';
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
//Load Composer's autoloader
require 'vendor/autoload.php';
// Output message
$msg = '';
// Now we check if the data from the login form was submitted, isset() will check if the data exists.
if (isset($_POST['email'])) {
// Prepare our SQL, preparing the SQL statement will prevent SQL injection.
$stmt = $con->prepare('SELECT * FROM accounts WHERE email = ?');
$stmt->bind_param('s', $_POST['email']);
$stmt->execute();
$stmt->store_result();
// Check if the email exists...
if ($stmt->num_rows > 0) {
$stmt->close();
// Update the reset code in the database
$uniqid = uniqid();
$stmt = $con->prepare('UPDATE accounts SET reset = ? WHERE email = ?');
$stmt->bind_param('ss', $uniqid, $_POST['email']);
$stmt->execute();
$stmt->close();
// Send email to the user
$mail = new PHPMailer(true);
try {
//Server settings
$mail->SMTPDebug = SMTP::DEBUG_SERVER; //Enable verbose debug output
$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 = 'xxx@gmail.com'; //SMTP username
$mail->Password = 'xxxx'; //SMTP password
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; //Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` encouraged
$mail->Port = 587; //TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` above
//Recipients
$mail->setFrom('xxx@gmail.com', 'Mailer');
$mail->addAddress('xxx@gmail.com'); //Add a recipient
//Content
$mail->isHTML(true); //Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
} }
?>
so when the code is submitted, i am unable to receive an email with no error messages only left with just a blank page. can anyone identify what i've done wrong??