redirect to an exit page send successful php form

0

Good morning I have a contact form PHP running but at the time of sending the send message of success I redirected to a blank page, as I could do to take me to my own page of form type: formulario-éxito.html sent successfully.

this is the code that has the form at the end preconfigured

<?php 
  if(isset($_POST['email'])){

    $name =$_POST["name"];
    $from =$_POST["email"];
    $phone=$_POST["phone"];
    $comment=$_POST["comment"];
    $budget=$_POST["budget"];

    // Email Receiver Address
    $receiver="[email protected]";
    $subject="Consulta a traves de formulario de contacto de Voy a Defenderte";

    $message = "
    <html>
    <head>
    <title>HTML email</title>
    </head>
    <body>
    <table width='50%' border='0' align='center' cellpadding='0' cellspacing='0'>
    <tr>
    <td colspan='2' align='center' valign='top'><img style=' margin-top: 15px; ' src='http://www.ociodinamicomultimedia.es/maquetas/voy/images/apple-touch-icon-114x114.png' ></td>
    </tr>
    <tr>
    <td width='50%' align='right'>&nbsp;</td>
    <td align='left'>&nbsp;</td>
    </tr>
    <tr>
    <td align='right' valign='top' style='border-top:1px solid #dfdfdf; font-family:Arial, Helvetica, sans-serif; font-size:13px; color:#000; padding:7px 5px 7px 0;'>Nombre:</td>
    <td align='left' valign='top' style='border-top:1px solid #dfdfdf; font-family:Arial, Helvetica, sans-serif; font-size:13px; color:#000; padding:7px 0 7px 5px;'>".$name."</td>
    </tr>
    <tr>
    <td align='right' valign='top' style='border-top:1px solid #dfdfdf; font-family:Arial, Helvetica, sans-serif; font-size:13px; color:#000; padding:7px 5px 7px 0;'>Email:</td>
    <td align='left' valign='top' style='border-top:1px solid #dfdfdf; font-family:Arial, Helvetica, sans-serif; font-size:13px; color:#000; padding:7px 0 7px 5px;'>".$from."</td>
    </tr>
    <tr>
    <td align='right' valign='top' style='border-top:1px solid #dfdfdf; font-family:Arial, Helvetica, sans-serif; font-size:13px; color:#000; padding:7px 5px 7px 0;'>Teléfono:</td>
    <td align='left' valign='top' style='border-top:1px solid #dfdfdf; font-family:Arial, Helvetica, sans-serif; font-size:13px; color:#000; padding:7px 0 7px 5px;'>".$phone."</td>
    </tr>
    <tr>
    <td align='right' valign='top' style='border-top:1px solid #dfdfdf; font-family:Arial, Helvetica, sans-serif; font-size:13px; color:#000; padding:7px 5px 7px 0;'>Reclamación Sobre:</td>
    <td align='left' valign='top' style='border-top:1px solid #dfdfdf; font-family:Arial, Helvetica, sans-serif; font-size:13px; color:#000; padding:7px 0 7px 5px;'>".$budget."</td>
    </tr>
    <tr>
    <td align='right' valign='top' style='border-top:1px solid #dfdfdf; border-bottom:1px solid #dfdfdf; font-family:Arial, Helvetica, sans-serif; font-size:13px; color:#000; padding:7px 5px 7px 0;'>Consulta:</td>
    <td align='left' valign='top' style='border-top:1px solid #dfdfdf; border-bottom:1px solid #dfdfdf; font-family:Arial, Helvetica, sans-serif; font-size:13px; color:#000; padding:7px 0 7px 5px;'>".nl2br($comment)."</td>
    </tr>
    </table>
    </body>
    </html>
    ";
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
// More headers
$headers .= 'From: <'.$from.'>' . "\r\n";
   if(mail($receiver,$subject,$message,$headers))  
   {
       //Success Message
      echo "Su mensaje fue enviado con éxito! En breve nos pondremos en contacto.";
   }
   else
   {    
     //Fail Message
      echo "Su mensaje no pudo ser enviado!";
   }

}
?>

Thanks

    
asked by Carmen 23.09.2018 в 10:34
source

2 answers

0

You can use:

  • header change the URL to another that you pass as a parameter.

  • file_get_contents on the same page shows you the content.

Example

header

header("Location: https://www.example.com/formulario-exito.html"); /
exit();

To get the content of the page without redirecting, you can use: file_get_contents

$pag= file_get_contents('https://www.example.com/formulario-exito.html');
    echo $pag;
    exit();

or

$pag= file_get_contents('formulario-exito.html');
    echo $pag;
    exit();
    
answered by 23.09.2018 в 15:54
0

I still can not comment, so I answer with an answer: If it works and send the email to the contact, then what you must replace are the ones in "Your message ..." for the previous answer:

header("Location: https://www.example.com/formulario-exito.html"); /
exit();

And in case of failure, for example, the same url with a query-string to indicate whether the message was sent well or not:

header("Location: https://www.example.com/formulario-exito.html?envio=mal"); /
exit();
    
answered by 23.09.2018 в 20:09