Changing the Result of a Form - Redirect to Another Page in the Submission

0

Hello,

I have a form and would like to know how to change the results of it.

Example: both for when the form is filled in successfully and for when an error occurs it redirects to a page of my choice.

I'm using the following code:

<form class="mbr-form" action="[email protected]" method="post" name="Meu Formulario">
      <div class="row row-sm-offset">
          <div class="col-md-4 multi-horizontal" data-for="name">
              <div class="form-group">
                   <label mbr-text class="form-control-label mbr-fonts-style" mbr-theme-style="display-7" for="name">Nome</label>
                   <input type="text" class="form-control" name="name" data-form-field="Name" required>
              </div>
          </div>
          <div class="col-md-4 multi-horizontal" data-for="email">
              <div class="form-group">
                   <label mbr-text class="form-control-label mbr-fonts-style" mbr-theme-style="display-7" for="email">Email</label>
                   <input type="email" class="form-control" name="email" data-form-field="Email" required>
              </div>
          </div>
          <div class="col-md-4 multi-horizontal" data-for="phone" hidden="hidden">
              <div class="form-group">
                   <label mbr-text class="form-control-label mbr-fonts-style" mbr-theme-style="display-7" for="phone" hidden="hidden">Produto</label>
                   <input type="tel" class="form-control" name="phone" data-form-field="Phone" hidden="hidden">
              </div>
          </div>
      </div>
      <div class="form-group" data-for="message">
          <label mbr-text class="form-control-label mbr-fonts-style" mbr-theme-style="display-7" for="message">Mensagem</label>
          <textarea type="text" class="form-control" name="message" rows="7" data-form-field="Message"></textarea>
      </div>

      <span mbr-buttons mbr-theme-style="display-4" data-toolbar="-mbrLink,-mbrBtnAdd,-mbrBtnMove" class="input-group-btn"><a href type="submit" class="btn btn-primary btn-form">ENVIAR MENSAGEM</a></span>
  </form>
    
asked by anonymous 18.07.2018 / 17:24

1 answer

0

HTML

<form class="mbr-form" action="" method="post" name="Meu Formulario">
  <div class="row row-sm-offset">
      <div class="col-md-4 multi-horizontal" data-for="name">
          <div class="form-group">
               <label mbr-text class="form-control-label mbr-fonts-style" mbr-theme-style="display-7" for="name">Nome</label>
               <input type="text" class="form-control" name="name" data-form-field="Name" required>
          </div>
      </div>
      <div class="col-md-4 multi-horizontal" data-for="email">
          <div class="form-group">
               <label mbr-text class="form-control-label mbr-fonts-style" mbr-theme-style="display-7" for="email">Email</label>
               <input type="email" class="form-control" name="email" data-form-field="Email" required>
          </div>
      </div>
      <div class="col-md-4 multi-horizontal" data-for="phone" hidden="hidden">
          <div class="form-group">
               <label mbr-text class="form-control-label mbr-fonts-style" mbr-theme-style="display-7" for="phone" hidden="hidden">Produto</label>
               <input type="tel" class="form-control" name="phone" data-form-field="Phone" hidden="hidden">
          </div>
      </div>
  </div>
  <div class="form-group" data-for="message">
      <label mbr-text class="form-control-label mbr-fonts-style" mbr-theme-style="display-7" for="message">Mensagem</label>
      <textarea type="text" class="form-control" name="message" rows="7" data-form-field="Message"></textarea>
  </div>

 <input type="submit" class="btn btn-primary btn-form">
</form>

Simple Email Script with PHP

if(isset($_POST['email'])) {
  $to = "[email protected]";
  $subject = "Form";
  $name = $_POST['name'];
  $email= $_POST['email'];
  /********o input phone está hidden *******/
  $phone = $_POST['phone'];
  $message = $_POST['message'];

  $body = "From: $name\n E-Mail: $email\n Phone: $phone\n Message:\n $message";

    if(mail($to, $subject, $body)){
       header('Location: http://www.google.com.br');
    }else{
       echo "Erro no envio";
    }
}
  

A good email script is PHPMailer

    /******* CODIGO EMAIL *******/

    /* Uma dica para envio de emails
    Baixe os arquivos  PHPMailerAutoload.php - class.smtp.php -  class.phpmailer.php
    em github - https://github.com/PHPMailer/PHPMailer/tree/5.2-stable
    Crie uma pasta  PHPMailer-master no mesmo diretório da sua aplicação PHP e 
    publique os arquivos baixados nesta pasta (PHPMailer-master).
    */
if(isset($_POST['email'])) {    

    $nome = $_POST['nome'];

    $email = $_POST['email'];

    $celular = $_POST['phone'];

    $mensagem = $_POST['message'];

    //email Destinatario
    $emailDest = "[email protected]";

    $email = Trim(str_replace("'","",$email));


    require_once 'PHPMailer-master/PHPMailerAutoload.php';

    $mail = new PHPMailer();
    $mail->IsSMTP();
    $mail->Host = 'smtp.dominio.com';
    $mail->Port = 587;
    $mail->SMTPAuth = true;
    $mail->IsHTML(true);
    $mail->Username = '[email protected]';
    $mail->Password = 'senha';

    //$mail->SMTPSecure = false; //Diz que nao tem tls/ssl
    $mail->SMTPSecure = 'tls';  
    //$mail->SMTPAutoTLS = false; //Diz que nao tem tls/ssl

    //$mail->SMTPDebug = 2; //Mostra os bugs

    //E-mail remetente
    $mail->From = $email;

    //Nome do remetente
    $mail->FromName = $nome;

    //Assunto da mensagem
    $mail->Subject = "teste mail";

    //Corpo da mensagem
    $mail->Body = "Celular ".$phone." - Mensagem ".$mensagem;

    //Corpo da mensagem em texto
    //$mail->AltBody = 'Conteudo do e-mail em texto';


    //Destinatario 
    $mail->AddAddress ($emailDest);

    $mail->Send();

}
    
19.07.2018 / 21:57