I made a cpf and email address. I've already put it to validate cpf and such, and I can send the email to the user who put the email there, but I need the registration to be done only if the email actually exists. In the case, would I have to do a single email confirmation of registration for when he clicked there, validate the registration, or would have some easier way? Because when I send the email to some nonexistent, it even confirms the registration and is placed in the bd. And how do I do this?
The code to send email:
<?php
require_once 'PHPMailer/PHPMailerAutoload.php';
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = 'host aqui';
$mail->Port = 587;
$mail->SMTPAuth = true;
$mail->IsHTML(true);
$mail->Username = 'emailr';
$mail->Password = 'senha';
$mail->SMTPSecure = false; //Diz que nao tem tls/ssl
$mail->SMTPAutoTLS = false; //Diz que nao tem tls/ssl
$mail->SMTPDebug = 2; //Mostra os bugs
//E-mail remetente (deve ser igual ao que esta enviando)
$mail->From = 'email';
//Nome do remetente
$mail->FromName ='Lojas';
//Assunto da mensagem
$mail->Subject = 'Texto';
//Corpo da mensagem
$mail->Body = 'Ola';
//Corpo da mensagem em texto
$mail->AltBody = 'Conteudo do e-mail em texto';
//Destinatario
$mail->AddAddress ('exemplo@email');
if ($mail->Send()) {
echo "e-mail enviado com sucesso";
echo'<script> alert("Cadastro realizado com sucesso!")</script>';
}else{
echo "Erro no envio do e-mail" .$mail->ErrorInfo;
}
?>
Registration code:
<label >CPF*:</label>
<input type="text" id="cpf" name="cpf" title="Digite o CPF no formato nnn.nnn.nnn-nn" class="form-control input-lg" placeholder="000.000.000-00" maxlength="14" required /><span id="resposta"></span>
<br>
<label inputemail>E-mail*:</label>
<input type="email" id="email" name="email" class="form-control input-lg email" placeholder="[email protected]" maxlength="50" required />
<br>
<br>
<button type="submit" class="btn btn-primary btn-lg btn-block" id="cadastrar" name="cadastrar" disbled/ >
<span class="glyphicon glyphicon-ok"></span>
<span id="cpf"></span>Cadastrar</button>
ValidaCadastro screen:
<?php
// ini_set('display_errors', '1');
ini_set('display_errors',1);
ini_set('display_startup_erros',1);
?>
<?php
require_once "config/conexao.php";
$var1 = $_POST['cpf'];
$var2 = $_POST['email'];
$query = "SELECT * FROM teste WHERE email = '$var2'";
$query = "SELECT * FROM teste WHERE cpf = '$var1'";
$querySelect = mysqli_query($conn, $query);
if (mysqli_num_rows($querySelect) > 0) {
echo"<script type='text/javascript'>alert('Cadastro existente.');window.location.href='cadastro.php';</script>";
}
$var1 = $_POST['cpf'];
$var2 = $_POST['email'];
if ($mail->Send()) {
echo "e-mail enviado com sucesso";
echo'<script> alert("Cadastro realizado com sucesso!")</script>';
if(!$stmt){
echo 'erro na consulta: '. $conn->error .' - '. $conn->error;
}
}else{
echo "Erro no envio do e-mail" .$mail->ErrorInfo;
}