联系表格空白;联系表格回复错误地址

时间:2013-05-09 14:35:44

标签: php forms contact-form

尝试制作无验证码,垃圾邮件拦截的联系表单。从用户的角度来看,它似乎正常工作,因为点击发送按钮后会出现感谢页面。

问题#1 :收到的电子邮件为空白,不包含已发送邮件的内容。发现这里的帖子听起来很相似,但提供的建议不适用:Contact form problem - I do receive messages, but no contents (blank page)

问题#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>

上面的代码中是否存在问题。 。 。或者还有其他事情可以继续?

2 个答案:

答案 0 :(得分:0)

当您的字段名称为$_POST['email'](小“e”)时,您尝试访问email - 请尝试使用$_POST['Email']

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

答案 1 :(得分:0)

首先你需要关闭报价$ body =“这是刚刚提交的表格:; 我说使用$ _REQUEST而不是$ _POST,因为这个变量是一个超全局数组,用于收集用GET和POST方法发送的数据。 我试过这个并且它有效 if(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`?>