Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/235.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
HTML5和php电子邮件表单未发送详细信息_Php_Html - Fatal编程技术网

HTML5和php电子邮件表单未发送详细信息

HTML5和php电子邮件表单未发送详细信息,php,html,Php,Html,我希望有人能帮我。我已经用HTML5和php创建了一个带有联系人表单的网页。当我按下提交按钮时,一封电子邮件被发送到它应该发送到的地方,但所有字段都是空白的 我知道我错过了一些简单的事情,但我就是看不到 这是HTML <form method="POST" action="submit.php"> <label form="HTML Form">Full Name:</label> <input maxlength="45" size="35" plac

我希望有人能帮我。我已经用HTML5和php创建了一个带有联系人表单的网页。当我按下提交按钮时,一封电子邮件被发送到它应该发送到的地方,但所有字段都是空白的

我知道我错过了一些简单的事情,但我就是看不到

这是HTML

<form method="POST" action="submit.php">
<label form="HTML Form">Full Name:</label>
<input maxlength="45" size="35" placeholder="Full Name" required name="name" id="name" type="text">
<label form="HTML Form">Phone Number:</label>
<input maxlength="45" size="35" placeholder="Phone" required name="phone" id="phone" type="text">
<label form="HTML Form">Email Address:</label>
<input maxlength="75" size="35" placeholder="Email Address" required name="email" id="email" type="email">
<label form="HTML Form">Comment:</label>
<textarea maxlength="300" placeholder="Comment"
    wrap="soft"
    rows="10"
    cols="40"
    name="comment" id="comment"
    required></textarea>
<input formmethod="post" value="Send" formaction="submit.php" type="submit">
<br>
</form>

全名:
电话号码:
电邮地址:
评论:

这里是php

<?php

/* checking if data was sent */
if(isset($_POST))
{
      foreach($_POST as $key => $field)
        {
            if(trim($field==""))
              echo "this field is required, your input is blank:   <b>$key</b>     <br>";
            $key=$field; //putting the response into variables
        }

    /* starting the email message */
    $to = "email@mywebsite.com"; // your email address
    $subject = "Contact form submission";
    $message = "Full Name: $name <br> Phone: $phone <br>";
    $message .= "Email Address: $email <br> Comment: <br> $comment";
    $headers = "From:" . $from."\r\n";
    $headers .= "MIME-Version: 1.0\r\n";
    $headers .= "Content-Type: text/html; charset=UTF-8\r\n";
    if(mail($to,$subject,$message,$headers))
    {
        echo "Email was sent";
    }
}
?>

您没有从POST数组中获取变量。 例如
$phone=$\u POST['phone']等

如果试图将
$\u POST
键名转换为变量,则需要执行以下操作:
$$key=$field
而不是
$key=$field。这些是。

错误在
$\u POST
变量的赋值中:

  foreach($_POST as $key => $field)
    {
        if(trim($field==""))
          echo "this field is required, your input is blank:   <b>$key</b>     <br>";
        $$key=$field; //putting the response into variables  # <------
    }
foreach($\u发布为$key=>$field)
{
如果(修剪($field==“”)
echo“此字段为必填字段,您的输入为空:$key
”;
$KEY=$field;//将响应放入变量{ julytas,如果它解决了问题,考虑接受答案。这里是如何返回,并用嘀嗒/检查标记做同样的操作,直到变成绿色。这通知了社区,找到了一个解决方案。否则,其他人可能认为问题仍然是开放的,并且可能想要发布(更多)。答案。