Form Validation - PHP

Asked

Viewed 100 times

0

I am trying to validate an email to send a form on , but it’s hard. My code is below, where I’m missing?

 $subject2 = utf8_decode ('Formulário 2016 - PRE-CADASTRO');
 $body2 = $mensagem_confirmacao;

 if (filter_var($mail, FILTER_VALIDATE_EMAIL)) 
 {      
     if (mail($to, $subject, $body, $headers)) {    
         mail($mail, $subject2, $body2, $headers);
         echo "<p>Inscrição enviada com sucesso!</p>";
    } else {
         echo "<p>Erro no envio, Houve algum erro no envio.Tente Novamente ";
    }

 } else { 
     echo "<p>E-mail ".$mail." inválido <a href='inscreva-se.php'>Houve algum erro no envio.Tente Novamente</a>!</p>"; 
 }  
  • friend it is interesting to put what problem is occurring so we can be more precise

  • He wants to validate emails @Otto

  • 1

    this part I understood @Danilo what is difficult to understand is what problem is having because the syntax of filter_var is correct at first. The more information the better the friend, most of the time in the error message this the solution.

  • @paulorpc what is the specific error? put to help you.

  • then friends the error can be visualized in this form: http://www.abimo.org.br/premioinovasaude/increva-se.php. I fill in all fields and when I click to send it the message that the "email is invalid" and does not send nda

1 answer

0

I don’t know exactly what your problem is, but the if of the mail() is duplicated. The right thing would be:

if ( mail($to, $subject, $body, $headers) ) 
{    
   echo "<p>Inscrição enviada com sucesso!</p>";
}
else
{
   echo "<p>Erro no envio, Houve algum erro no envio.Tente Novamente</p> ";
}
  • when I try to send the form the second echo message appears and does not let me send. if possible check the link: http://www.abimo.org.br/premioinovasaude/increva-se.php

  • paulorpc this is good, I say this because it means that the code above is working. I explain: If the Else echo message is showing up it is because Function mail() is returning false. What needs to be seen then is the configuration of the email service configured in php.ini (eg/usr/sbin/sendmail). Another alternative to email PHP is Phpmailer https://github.com/PHPMailer/PHPMailer with it you can set up an external server like gmail

Browser other questions tagged

You are not signed in. Login or sign up in order to post.