简体   繁体   English

PHP联络表格无效

[英]PHP contact form doesn't work

i've been a couple hours trying to solve this but i can't, the problem is that send the message but it doesn't redirect with header 我已经花了几个小时试图解决这个问题,但是我不能,问题是发送消息但它没有重定向到标题

This is action.php file 这是action.php文件

<?php

$nombre=$_POST['nombre'];
$correo=$_POST['correo'];
$telefono=$_POST['telefono'];
$consulta=$_POST['consulta'];

$destino="nochetangotours@gmail.com";

$asunto='Reserva Contacto';

$mensaje='Nombre: '.$nombre."\r\n";
$mensaje='Correo: '.$correo."\r\n";
$mensaje='Telefono: '.$telefono."\r\n";
$mensaje='Consulta: '.$consulta."\r\n";


$remitente="From: $nombre <$correo>";


mail($destino, $asunto, $mensaje, $remitente);

header('Location:index.php');

?>` 

This is index.php file. 这是index.php文件。 Maybe there is something wrong in here, i cant see the mistake 也许这里有问题,我看不到错误

<form id="formulario1" name="formulario1" action="enviar.php" method="post">
<table>
<tr>
<td class="nombre_form"> </td>
<td><input class="campo_form1"  type="text" name="nombre"id="nombre"placeholder="Nombre*" required/>  </td>
</tr>
<tr>
<td class="nombre_form"></td>
<td><input class="campo_form"   type="email" name="correo" id="correo" placeholder="Email*" required/></td>
</tr>
<tr>
<td class="nombre_form"></td>
<td><input class="campo_form"   type="text" name="telefono"  id="telefono"    placeholder="Telefono"/></td>
</tr>
<tr>
<td class="nombre_form"></td>
<td><textarea class="campo_mensaje"  name="consulta" rows="8" id="consulta" placeholder="Mensaje*" required></textarea></td>
</tr>
</table>
<input class="campo_enviar" type="submit" name="enviar" value="Enviar"/>
</form>

Now im trying that but it doesn't work neither Thank you! 现在,我正在尝试,但也没有用,谢谢!

try 尝试

<?php
$nombre=$_POST['nombre'];
$correo=$_POST['correo'];
$telefono=$_POST['telefono'];
$consulta=$_POST['consulta'];
$destino="nochetangotours@gmail.com";
$asunto='Reserva Contacto';
$mensaje='Nombre: '.$nombre."\r\n";
$mensaje='Correo: '.$correo."\r\n";
$mensaje='Telefono: '.$telefono."\r\n";
$mensaje='Consulta: '.$consulta."\r\n";
$remitente="From: $nombre <$correo>";
mail($destino, $asunto, $mensaje, $remitente);
header('Location:index.php');
?>
<form id="formulario1" name="formulario1" action="" method="post">
<table>
<tr>
<td class="nombre_form"> </td>
<td><input class="campo_form1"  type="text" name="nombre" id="nombre"placeholder="Nombre*" required/>  </td>
</tr>
<tr>
<td class="nombre_form"></td>
<td><input class="campo_form"  type="email" name="correo" id="correo" placeholder="Email*" required/></td>
</tr>
<tr>
<td class="nombre_form"></td>
<td><input class="campo_form"   type="text" name="telefono"  id="telefono"    placeholder="Telefono"/></td>
</tr>
<tr>
<td class="nombre_form"></td>
<td><textarea class="campo_mensaje"  name="consulta" rows="8" id="consulta" placeholder="Mensaje*" required></textarea></td>
</tr>
</table>
<input class="campo_enviar" type="submit" name="enviar" value="Enviar"/>
</form>
  <?php
    if(isset($_POST[something]))
    {
    $nombre=$_POST['nombre'];
    $correo=$_POST['correo'];
    $telefono=$_POST['telefono'];
    $consulta=$_POST['consulta'];

    $destino="nochetangotours@gmail.com";

    $asunto='Reserva Contacto';
    $mensaje = '';
    $mensaje .='Nombre: '.$nombre."\r\n";
    $mensaje .='Correo: '.$correo."\r\n";
    $mensaje .='Telefono: '.$telefono."\r\n";
    $mensaje .='Consulta: '.$consulta."\r\n";


    $remitente="From: $nombre <$correo>";


    mail($destino, $asunto, $mensaje, $remitente);

     header('Location:redireccion.php');
    }
    ?>

You are redirecting at starting of the page through `header' 您正在通过“页眉”在页面开始处进行重定向

then how will your code will work? 那么您的代码将如何工作?

so put your header after end of the code 所以把你的头放在代码的末尾

<?php


$nombre=$_POST['nombre'];
$correo=$_POST['correo'];
$telefono=$_POST['telefono'];
$consulta=$_POST['consulta'];

$destino="nochetangotours@gmail.com";

$asunto='Reserva Contacto';

$mensaje='Nombre: '.$nombre."\r\n";
$mensaje='Correo: '.$correo."\r\n";
$mensaje='Telefono: '.$telefono."\r\n";
$mensaje='Consulta: '.$consulta."\r\n";


$remitente="From: $nombre <$correo>";


mail($destino, $asunto, $mensaje, $remitente);

header('Location:redireccion.php');
exit; 

?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM