2
I signed up with Cpf and email. I already put 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 really exists. In this case, I would have to make a single email confirmation of registration for when he click there, validate the registration, or would have some easier way? Because when I send the email to some non-existent one, it still 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>
Screen of validationCadastro:
<?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;
}
The registration must exist anyway, the confirmation email is just to confirm. What you can do is only release the access after the email is confirmed.
– Roberto de Campos
So...I put an email that does not exist, and even then the registration is successfully done. And I know that the email does not exist because I have checked it
– Maria
it’s just Cpf and email?
– user60252
Yes. I put Cpf as PK, and I checked Cpf to see if it exists or not. Now I have to validate the email, to know if it exists or not
– Maria
I think of two solutions: first send to the registration email ->>
Clique <a href='http://dominio.com/ativar.php?cpf=".$cpf."&email=".$email."'>aqui</a> para ativar seu cadastro.
Dai vc take these values and make Insert in the bank– user60252
But how exactly do I do that? You can give an example?
– Maria
What is your difficulty? Email the user with this line?
– user60252
I can send email to the customer, what I do not know is send an email with confirmation link, in case he receives the email, have to click the link, then when click the email goes to bd
– Maria
have to put exactly this line in the body of the email message
– user60252
I wouldn’t advise sending the CPF on the validation link. Since it is a confidential data, it would be better to have in the bank a column with a unique code for each user of some 8 characters (letters and numbers), then creates the validation link using this code + email.
– Sam
@Yes, but how exactly do I do that?
– Maria
@In the content of the message will not show any Cpf data
– Maria
@The extra job to clean bank with unreturned, if you do not want to expose Cpf in link make use of localStorage which would be the second solution
– user60252
Put your email code in the question
– user60252
@Leocaracciolo ready
– Maria
If any answer has solved your question, be sure to mark it as accepted, see how and why in https://pt.meta.stackoverflow.com/questions/1078/como-e-por-que-aceitar-uma-resposta/1079#1079
– user60252