I am trying to send email from a xampp server with below php code. Php code seems to work fine as it gives all success and error messages but I am not recieving any mails on email I provide in form.
<?php
if(isset($_POST['submit'])){
$email = $_POST['email'];
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {// Validate email address
$message = "Invalid email address please type a valid email!";
}
else
{
$query = $con->prepare("SELECT username FROM members where email=:email");
$query->execute(array(':email'=>$email));
$row = $query->fetch(PDO::FETCH_ASSOC);
if($query->rowCount() == 1) {
$encrypt = md5(1290*3+$row['username']);
$message = "Your password reset link has been send to your e-mail address. Check your mail and click on the link therein.";
$to=$email;
$subject="Password Recovery";
$from = 'mydemo.com';
$body='Hi, <br/> <br/>Your username is '.$row['username'].' <br><br>Click here to reset your password http://localhost/mydemo/reset.php?encrypt='.$encrypt.' <br/> <br/>--<br>';
$headers = "From: " . strip_tags($from) . "\r\n";
$headers .= "Reply-To: ". strip_tags($from) . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
mail($to,$subject,$body,$headers);
}
else
{
$message = "Account not found please enter email you provided during sign up!";
}
}
}
<form action="" method="POST">
<legend>Forgot your password!</legend>
<input type="email" name="email" id="email" required="required" maxlength="35" placeholder="Enter your email here..."/>
<input type="submit" name="submit" id="submit" value="Submit"/>
</form>
<div id="message"><?php echo $message; ?></div>
I have also made following changes to C:\xampp\php\php.ini
and c:\xampp\sendmail\sendmail.ini
actually I had two php.ini development and production. I made changes to php-ini-development
SMTP=smtp.gmail.com
smtp_port=587
sendmail_from = gmailid@gmail.com
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
[sendmail]
smtp_server=smtp.gmail.com
smtp_port=587
error_logfile=error.log
debug_logfile=debug.log
auth_username=gmailid@gmail.com
auth_password=gmailpassword
force_sender=my-gmailid@gmail.com