0

我正在尝试制作一个无验证码、阻止垃圾邮件的联系表格。从用户的角度来看,它似乎在工作,因为在单击发送按钮后会出现感谢页面。

问题 #1:到达的电子邮件是空白的,不包含已发送消息的任何内容。在这里找到一个听起来相似的帖子,但提供的建议不适用: 联系表格问题 - 我确实收到了消息,但没有内容(空白页)

问题#2:回复消息也显示在同一个收件箱中,而不是发送到表单用户的地址——在测试时,它是我自己的。

的HTML:

<form method="post" action="submit.php">
 <p>Name:<br>
 <input type="text" name="Name" id="Name" /></p>

 <p>Phone:<br>
 <input type="text" name="Phone" id="Phone" /></p>

 <p>Email:<br>
 <input type="text" name="Email" id="Email" /></p>

 <p class="antispam">Leave this empty:<br />
 <input name="url" /></p>

 <p style="color:#06C;">Forward to:<br>
 <input type="text" name="Forwardto" id="Forwardto" /></p>

 <p>Message:<br />
 <textarea name="Message" rows="20" cols="20" id="Message"></textarea></p>

 <p><input type="submit" value="Send" class="submit-button" /></p>
</form>

PHP(删除了我的实际地址):

<?php

if(isset($_POST['url']) && $_POST['url'] == ''){

    $youremail = '----@----.com';

    $body = "This is the form that was just submitted:
    Name:  $_POST[name]
    Phone:  $_POST[phone]
    E-Mail: $_POST[email]
    Forward to: $_POST[forwardto]
    Message: $_POST[message]";

    if( $_POST['email'] && !preg_match( "/[\r\n]/", $_POST['email']) ) {
      $headers = "From: $_POST[email]";
    } else {
      $headers = "From: $youremail";
    }

    mail($youremail, 'Contact Form', $body, $headers );

}

?>

相关的CSS:

<style type="text/css">
.antispam { display:none;}
</style>

是上面代码的问题。. . 还是可能发生其他事情?

4

2 回答 2

0

您尝试$_POST['email']在字段名称为email(小“e”)时访问 - 尝试$_POST['Email']改用

第二个问题 -mail()函数的第一个参数是您希望将其发送到的电子邮件,即$_POST['Email']. 现在您正尝试将其发送到硬编码的$youremail.

于 2013-05-09T14:41:24.150 回答
0

首先你需要关闭报价 $body = "This is the form that was just paid: " ; 我说使用 $_REQUEST 而不是 $_POST 因为这个变量是一个超全局数组,用于收集使用 GET 和 POST 方法发送的数据。我已经尝试过了,如果 (isset($_REQUEST['email'])) 在此处输入代码`{

      //Email information
      $admin_email = "myemail.co.uk";
      $subject = "This is the form that was just submitted";
      $email = $_REQUEST['email'];
      $comment = $_REQUEST['comment'];
      $full_name = $_REQUEST['full_name'];

      //send email
      mail($admin_email, "$subject", "message:" . $comment, "From:" . $email,     `enter code here`enter code here`$full_name);

       //Email response if needed
      echo "Thank you for contacting us!";
       }

      //if "email" variable is not filled out, display the form
       else  
        {
        enter code here`enter code here`?>
        enter code here`<p>Email us at <i>website name.com</i></p>
        enter code here`<?php
        enter code here`}
        enter code here`die();
        enter code here`?>
于 2016-05-03T00:48:32.773 回答