-3
I have a system inside the xampp I’m developing, I tried to use the php mail function to send a password recovery email, but it doesn’t work. Someone can help me there for days that I have with this problem.
Code:
<?php
session_start();
include('../classes/conexao.php');
if (empty($_POST['email'])) {
$_SESSION['campos'] = true;
header('Location: ../view/recupera_senha.php');
exit();
} else {
$email = mysqli_real_escape_string($conexao, trim($_POST['email']));
if(!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$_SESSION['invalido'] = true;
header('Location: ../view/recupera_senha.php');
exit();
} else {
$query = "SELECT COUNT(*) AS reg FROM usuarios WHERE email = '$email'";
$result = mysqli_query($conexao, $query);
$row = mysqli_fetch_assoc($result);
if ($row['reg'] == 1) {
$novasenha = substr(md5(time()), 0, 6);
$senhacriptografada = md5(md5($novasenha));
try {
if(mail($email, "Title", "Mensagem", "Cabeçalho")) {
$query = "UPDATE usuarios SET senha = '$senhacriptografada' WHERE email = '$email'";
$result = mysqli_query($conexao, $query);
$_SESSION['enviado'] = true;
header('Location: ../view/recupera_senha.php');
exit();
}
} catch (Exception $e) {
echo 'Exceção capturada: ', $e->getMessage(), "\n";
}
} else {
$_SESSION['inexistente'] = true;
header('Location: ../view/recupera_senha.php');
exit();
}
}
}
?>
Possible duplicate of How to send email with PHP?
– Woss