2013-03-04 66 views
0

即时通讯在这个链接http://jardineselectricos.com/xtatanx/contacto.php做一个表格,一切工作正常,形式只是给我发送电子邮件时填充,但是,当我recive回声输出所有网站起来。我想知道如何将输出放在我想要的位置。这是我的代码。回声php定位

HTML:

<form method="post" action="contacto.php" id="form"> 
    <label for="nombre">Nombre: </label> 
    <input type="text" name="nombre" placeholder="Su nombre"/> 
    <label for="correo">Correo electrónico: </label> 
    <input type="email" name="email" placeholder="[email protected]"/> 
    <label for="numero-telefonico">Teléfono móvil: </label> 
    <input type="text" name="telefono" placeholder="Introducir nº de telf" /> 
    <label for="mensaje">Mensaje: </label> 
    <textarea name="mensaje" cols="20" rows="6" placeholder="Escriba un mensaje breve..."></textarea> 
    <input type="submit" id="enviar" name="enviar" value="Enviar"> 
    <span id="respuesta"> 
     <?php 
       $nombre = $_POST['nombre']; 
       $email = $_POST['email']; 
       $numero = $_POST['telefono']; 
       $mensaje = $_POST['mensaje']; 
       $from = 'From: UsuarioStrategyResearch'; 
       $to = '[email protected]'; 
       $subject = 'Contacto Strategy Research'; 

       $body = "De: $nombre\n E-Mail: $email\n Movil: $numero\n Mensaje:\n $mensaje"; 

       if ($_POST['enviar']) { 
       if (mail ($to, $subject, $body, $from)) { 
        echo '<p>Tu mensaje ha sido enviado, pronto nos pondrémos en contacto.</p>'; 
       } else { 
        echo '<p>Ha habido un error y el mensaje no ha podido ser enviado.</p>'; 
       } 
      } 
      ?> 
    </span> 
    </form> 

输出始终把它像网站中,如果我使用的垃圾邮件或DIV它并没有改变,或者如果我在页脚positionae还是无处不在,它只是回声在同一个地方。我很感谢你的帮助,非常感谢你。

+0

那么,你想输出去任何HTML之前调用mail? – Terry 2013-03-04 02:04:54

+0

我希望输出到id =“respuesta”的范围内,所以我认为它应该出现在提交按钮的下面,而是出现在文档的中间 – 2013-03-05 15:24:54

回答

1

该页面会显示您的问题

警告:无法修改标题信息 - 在/ home头已经发出(输出开始/home/jardines/public_html/xtatanx/contacto.php:57)/怡和/的public_html/xtatanx /上线70

contacto.php这意味着mail函数需要修改HTTP头,但他们已经发送,因为你已经开始输出HTML。

你需要确保你输出

<?php 
// At the top of the file, before any HTML is output 
$successfulMail = mail ($to, $subject, $body, $from); 
$nombre = $_POST['nombre']; 
$email = $_POST['email']; 
$numero = $_POST['telefono']; 
$mensaje = $_POST['mensaje']; 
$from = 'From: UsuarioStrategyResearch'; 
$to = '[email protected]'; 
$subject = 'Contacto Strategy Research'; 
$body = "De: $nombre\n E-Mail: $email\n Movil: $numero\n Mensaje:\n $mensaje"; 
$mailMsg = ''; 
if ($_POST['enviar']) { 
    // Here's the trick, can't call mail after HTML has been output 
    if (mail ($to, $subject, $body, $from)) { 
     $mailMsg ='<p>Tu mensaje ha sido enviado, pronto nos pondrémos en contacto.</p>'; 
    } else { 
     $mailMsg ='<p>Ha habido un error y el mensaje no ha podido ser enviado.</p>'; 
    } 
} 
?>  
... 
<form method="post" action="contacto.php" id="form"> 
    <label for="nombre">Nombre: </label> 
    <input type="text" name="nombre" placeholder="Su nombre"/> 
    <label for="correo">Correo electrónico: </label> 
    <input type="email" name="email" placeholder="[email protected]"/> 
    <label for="numero-telefonico">Teléfono móvil: </label> 
    <input type="text" name="telefono" placeholder="Introducir nº de telf" /> 
    <label for="mensaje">Mensaje: </label> 
    <textarea name="mensaje" cols="20" rows="6" placeholder="Escriba un mensaje breve..."></textarea> 
    <input type="submit" id="enviar" name="enviar" value="Enviar"> 
    <span id="respuesta"><?php echo $mailMsg ?> </span> 
    </form>