3
I have a PHP that sends an email from a contact form, when this in the condition of the captcha verification, I receive the sent message, but the email is not delivered, and when I remove the condition the email arrives normal. Follow the PHP code (The Submit is done by ajax)
<?php
$captcha = $_POST['captcha'];
if (!empty($_POST['captcha'])) {
$resposta = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=SECRET-KEY&response=".$captcha."&remoteip=".$_SERVER['REMOTE_ADDR']);
if ($resposta.success) {
$to = "[email protected]";
$nome = $_POST["nome"];
$email = $_POST["email"];
$mensagem = $_POST["mensagem"];
$celular = $_POST["celular"];
$assunto = $_POST["assunto"];
$txt = "MENSAGEM: $mensagem". "\r\n" . "CELULAR: $celular". "\r\n" . "NOME: $nome";
$headers = "From: $email";
if ((empty($nome))||(empty($email))||(empty($celular))||(empty($mensagem))||(empty($assunto))) {
print('Preencha os campos');
} else {
$envio = mail($to,$assunto,$txt,$headers);
if ($envio) {
print('Enviado');
}else{
print('Erro');
}
}
} else {
print('Erro');
}
} else {
print('Marque o Captcha');
}
?>
Returns some of the prints?
– Miguel
Yes, I printed all normal ones by not checking captcha, if not all fields are filled and when sending.
– Vinicius
What do you print? enters what condition?
– Miguel
If you check the captcha and fill in all the fields, I printed: Sent. The prints come out as if they were working, but the email doesn’t arrive.
– Vinicius
If you are on localhost you will not send unless you have an email server installed
– Miguel
It is on a server. As I said: when I remove the mail() from this condition, it works, that is, I receive the email sent by php.
– Vinicius
I think I know what’s happening... It must be because your email client is viewing it as spam. I’m going to post a possible solution
– Miguel
Depending on the hosting does not accept this function, uses Phpmail.
– PauloFlesch