【问题标题】:PHP question. I get email, but it doesn't have user input from websitePHP 问题。我收到电子邮件,但没有来自网站的用户输入
【发布时间】:2020-03-21 10:08:19
【问题描述】:

PHP 代码从服务器向我发送了一封电子邮件,但用户输入为空或“空白”。我只收到:“发件人:\电子邮件:\主题:\消息:”就是这样。

如何修复我的 PHP 和/或 HTML 代码以接收来自表单的用户输入?这是我现有的 HTML 和 PHP 代码,它不会从表单向我发送任何“用户输入”。

PHP HTML

感谢任何可以提供帮助的人!

【问题讨论】:

  • 欢迎来到这个平台。您可能需要查看您的表单 enctype 属性。我们本来可以看的,但你没有把它贴在这里。此外,您可能还想通过此资源 (stackoverflow.com/help/how-to-ask) 了解如何更好地在此平台上提出问题

标签: php input


【解决方案1】:

考虑一下这是你的表单

<form action="yourpage.php" method="post">
<input type="text" name="name" placeholder="enter name" required>

<input type="submit" name="submit" placeholder="enter name">

确保&lt;form action="" 链接到正确的页面并且method="post" 应该在那里。 如果当前页面上存在表单,即在我的情况下是 yourpage.php,则将表单操作留空。我还建议在输入字段末尾添加 required 例如

<input type="text" name="name" placeholder="enter your name" required>

因为它迫使用户在那里写一些值,所以你不会得到一个空值

接下来是你的 php 文件,只需在第一行添加代码

if(isset($_POST['submit'])) {

上面的代码验证用户点击了提交按钮,所以整体代码看起来像

    <?php
if(isset($_POST['submit'])) {
    $name = $_POST['name'];
    $email = $_POST['email'];
    $phone = $_POST['phoneT'];
    $call = $_POST['call'];
    $website = $_POST['website'];
    $priority = $_POST['priority'];
    $type = $_POST[itypel];
    $message = $_POSTUmessagefl;
    $formcontent = "  From:$name \n  Phone: $phone \n  CallBack: $call \n Website: $website \n  Priority: $priority \n Type: $type \n  Message:    $message";
    $recipient = "YOUREMAIL@HERE.COM";
    $subject - "Contact  Form";
    $mailheader = "From:                 $email                     \r\n";
    mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
    echo "Thank You!" . "           -" . "<a  href=iform.htmll
    style='text-decoration:none;color:#ff0099;'>  Return
    Home</a>";
}
?>

【讨论】:

  • 感谢您的帮助,但这仍然不起作用!
猜你喜欢
  • 2014-06-16
  • 1970-01-01
  • 2014-12-18
  • 2018-12-04
  • 1970-01-01
  • 2019-11-05
  • 2020-11-29
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多