【问题标题】:PHP Contact Form sending blank emails, text input not showing up in emailPHP联系表单发送空白电子邮件,文本输入未显示在电子邮件中
【发布时间】:2017-11-21 02:22:17
【问题描述】:

我的 php 电子邮件表单有问题。我之前问过这个问题,但意识到它措辞不当,所以我删除了它并再次尝试。我是这个论坛的新手,我还在习惯如何发帖。

我的 html 联系表单正在处理,但发送的是空白电子邮件。

这是我的 HTML 表单:

<form id="contact_form" class="cf" name="contact_form" action="mailscript.php" method="POST">

    <div id="left_form_container"> 
      <div class="half_left_cf">
        <input type="text" name="name" id="input_name" placeholder="Name">
        <input type="email" name="email" id="input_email" placeholder="Email address">
        <input type="text" name="subject" id="input_subject" placeholder="Subject">
      </div>   
    </div>

    <div id="right_form_container">
        <div class="half_right_cf">
            <textarea name="message" id="input_message" type="text" placeholder="Message"></textarea>
            <div id="submit_container">
            <input type="submit" name="submit" value="Submit" id="input_submit">
            </div>
        </div>  
    </div>

</form>

这是我的 php 代码:

<?php

$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];

$to = "mail@thomasjeffery.design";
$body = "From: ".$name."\n E-Mail: ".$email."\n Message:\n" .$message;



if(mail ($to, $subject, $body)){


echo "<script>
alert('Thank you for sending your message!');
window.location.href='index.php';
</script>";}
    else {echo "Mail was not sent!";}


?>

电子邮件有效(它发送一封电子邮件),并且回显显示“谢谢”并将用户返回到主页,但联系表单中的表单信息没有被发送..

相反,电子邮件只是写着: “从: 电子邮件: 消息:"。

谁能告诉我为什么它不包括我的 html 表单中的输入字段?这似乎很简单,但我似乎无法弄清楚。

【问题讨论】:

  • echo $_POST['name'] 的输出是什么?
  • 另外你通过表格发送什么,有特殊字符吗?

标签: php forms email


【解决方案1】:

您可以尝试对您的请求进行一些调试,例如:

echo "<pre>";
print_r($_REQUEST);
print_r($_GET);
print_r($_POST);
echo "</pre>";

另外,您必须确保您的表单方法属性是 POST 或 GET 方法。

【讨论】:

  • 它只是以“array ()”的形式出现:/所以我认为输入实际上根本没有通过。
  • 是的,如果是空数组,那肯定是你的数据提交有问题。我的建议是,仔细检查您的
    ,在操作页面中添加我之前提到的那些调试代码,然后添加 exit() 函数。确保从表单中获取数据。
【解决方案2】:

从您的代码看来,您似乎忘记添加表单开始标签。 "&lt;form&gt;"

例如。

<form method="post" action="thepagetosubmit.php">

可能的完整代码。

 <form method="post" action="thepagetosubmit.php">
    <div id="left_form_container"> 
      <div class="half_left_cf">
        <input type="text" name="name" id="input_name" placeholder="Name">
        <input type="email" name="email" id="input_email" placeholder="Email address">
        <input type="text" name="subject" id="input_subject" placeholder="Subject">
      </div>   
    </div>

    <div id="right_form_container">
        <div class="half_right_cf">
            <textarea name="message" id="input_message" type="text" placeholder="Message"></textarea>
            <div id="submit_container">
            <input type="submit" name="submit" value="Submit" id="input_submit">
            </div>
        </div>  
    </div>

</form>

【讨论】:

  • 抱歉,我添加的开始表单标签似乎没有粘贴过来。但我确实有。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-12-29
  • 1970-01-01
  • 1970-01-01
  • 2017-09-13
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多