Hey guys, This is the other issue that I have failed to fix which is very frustrating but I have have spent a long time trying too so need help as I have to deliver a working version before Monday which will be the end of my learning project. Any help would be very much appreciated.
Problem: I’ve created a password reset system using PHPMailer and Gmail SMTP. I get no errors but on submitting the form no email is received.
Here is the code:
forgotPass_form.php
<?php
ob_start();
require "dbconnection.php";
if (isset($_POST["forgot_password"])){
if(!empty($_POST["member-email"])) {
$email =trim($_POST["member-email"]);
} else {
$error_message = "<li>Email is requred</li>";
}
if(empty($error_message)){
$query = $con->prepare("SELECT email FROM profiles WHERE email =?");
$query->execute(array($email));
$member = $query->fetchAll(PDO::FETCH_ASSOC);
}
if (!empty($member)){
$msg='yes';
echo "<script type='text/javascript'>alert('$msg');</script>";
require_once ("forgotPass.php");
} else {
$error_message = "No Email Found";
}
}
var_dump($_POST)
?>
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<div id="wrapper">
<div>
<form id="formforget" name="formforget" method="post">
<h3>Please enter your email to reset your password</h3>
<?php if(!empty($success_message)) { ?>
<div class="success_message"><?php echo $success_message ?>
<?php } ?>
<?php if(isset($error_message)) { ?>
<div class="error_message"><?php echo $error_message; ?></div>
<?php } ?>
<input type="email" name="member-email" placeholder="Enter a valid email" required>
<input type="submit" value="submit" name="forget-password" id="forget-password">
</form>
</div>
</div>
</div>
</body>
</html>
forgotPass.php
<?php
require("class.phpmailer.php");
require("PHPMailerAutoload.php");
define("pusheen_blog", "http://localhost:8080/TEST");
$mail= new PHPMailer; //enables
//Server settings
$mail->SMTPDebug = 0; // Enable
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = "smtp.gmail.com"; // Set host name
$mail->SMTPAuth = true; // Set this true if SMTP host requires authentification to send mail
$mail->Username = "example@example.com"; // Profile username
$mail->Password = "Updowninout22$"; // Profile email password
$mail->SMTPSecure = "tls"; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
//Recipients
$mail->setFrom('example@example.com', 'WomenWhoCan');
$mail->FromName = "WomenWhoCan";
$mail->addAddress('$_POST', 'email'); // Add a recipient
$mail->addReplyTo('womenwhocan.org.gmail.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 = "Forget Password Recovery";
$mail->Body="<div>".$member[0]["name"]."<br><br><p>Click here to recover your password<br>
<a href='".pusheen_blog."resetPassword.php?name=".$member[0]["name"]."'> ".pusheen_blog.
"resetPassword.php?name=".$member[0]["name"]."</a><br><br></p>Regards<br> Admin.</div>";
if (!$mail->send()) {
$error_message = "Mailer Error : " . $mail->ErrorInfo;
} else {
$success_message = "Your request has been submitted successfully";
}
?>
dbconnection.php
<?php
try {
$con = new PDO ("mysql:host=localhost; dbname=pusheen_blog", "root", "");
//echo "connected";
$con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch(PDOException $e)
{
echo "error" .$e->getMessage();
}