Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/276.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
如何创建php表单处理程序并与现有html web表单集成?_Php_Html_Forms - Fatal编程技术网

如何创建php表单处理程序并与现有html web表单集成?

如何创建php表单处理程序并与现有html web表单集成?,php,html,forms,Php,Html,Forms,这就是我面临的问题。我创建了一个非常简单的web表单: <form method="post" action="#"> <div class="field"> <label for="name">Name</label> <input name="name" id="name" type="text"> </div>

这就是我面临的问题。我创建了一个非常简单的web表单:

    <form  method="post"  action="#">
                  <div  class="field"> <label  for="name">Name</label>
                    <input  name="name"  id="name"  type="text"> </div>
                  <div  class="field"> <label  for="email">Email</label> <input

                       name="email"  id="email"  type="email"> </div>
                  <div  class="field"> <label  for="message">Message</label> <textarea

 name="message"  id="message"  rows="4"></textarea> </div>
                  <ul  class="actions">
                    <li><input  value="Send Message"  type="submit"></li>
                  </ul>
                </form>

名称
电子邮件
消息

我需要知道如何使用此表单将用户输入的数据发送到我的电子邮件地址admin@nue-tech.uk我知道这可以用PHP实现,但我不确定如何实现,因为我不熟悉PHP。如果有人能给我指出正确的方向,告诉我如何做到这一点,以及我应该把PHP文件放在什么地方,那就太棒了

您可以复制下面的代码并将其粘贴到HTML下面的HTML文件中。在html中,将action属性设置为空。不要忘记将文件扩展名更改为
.php

<?php 
if(isset($_POST['submit'])){
$to = "admin@nue-tech.uk";
$from = $_POST['email'];
$name = $_POST['name'];
$subject = "Blablabla"; //Write whatever you want here
$message = $name . "wrote the following:" . "\n\n" . $_POST['message'];

$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
header('location: thank-you.html'); //redirects the user to another page if the mail was send succesfully
} else {
header('location: contact.html'); //if it was not send succesfully it redirects to the contact page again
exit(0);
}
?>
你也可以使用

echo "Something went wrong. Try again later" 
或者类似的东西。
我强烈建议您在或上搜索和学习。

如果您尝试一个名为“谷歌”(Google)的网站,您也会找到大量的教程。只需搜索“php电子邮件表单”,代码绝对不应进入
中。它试图设置在任何页面内容之前必须输出的HTTP头。哦,你说得对,谢谢
echo "Something went wrong. Try again later"