简体   繁体   English

PHP表单操作和提交

[英]PHP form action and submittal

I just wrote my first PHP code or attempted to anyways. 我只是写了我的第一个PHP代码,还是尝试了。 A very simple form for email submission. 一种非常简单的电子邮件提交表格。 It's not submitting right however. 但是它没有正确提交。 Can anyone guide me towards where I'm going wrong? 谁能指导我找出问题所在? Thanks. 谢谢。

Here is the form code on this .html page 这是此.html页上的表单代码

<form action="request-info.php" method="post" name="request-info">

<input name="name" type="text" value="Name">

<input name="email" type="text" value="E-mail Address">

<p>More information for</p>
<input name="family" type="radio" value="Family Member">Family
<br>
<input name="friend" type="radio" value="Friend">Friend
<br>
<input name="myself" type="radio" value="Myself">Myself
<br>
<input name="submit" type="button" value="Submit"> | <input name="reset" type="reset" value="Reset">
</form>

Here is what I have on the action page. 这是操作页面上的内容。 I think this is where I may be wrong. 我认为这可能是我错的地方。 Should I have an something in here relating to the submit button? 我是否应该在此处提供与“提交”按钮有关的内容?

<?php

$name = $_POST['name'];
$email = $_POST['email'];
$family = $_POST['family'];
$friend = $_POST['friend'];
$myself = $_POST['myself'];
$to = "example@example.com";
$subject = "Information Request";
mail ($to, $subject, $info, "From: " . $name . $email);
echo "Your request has been sent!";

?>

Thanks 谢谢

Change 更改

<input name="submit" type="button" value="Submit">

to

<input name="submit" type="submit" value="Submit">

Also, you don't need a value with the submit, it's optional. 此外,您不需要提交值,它是可选的。

To submit, it should have a input type submit 要提交,其输入类型应为Submit

<input name="submit" type="button" value="Submit">

In addition, for the php part to check if the mail is sent, you should do: 另外,要让php部分检查邮件是否已发送,您应该执行以下操作:

if(mail ($to, $subject, $info, "From: " . $name . $email)){
  echo "Your request has been sent!";
} else {
  echo "Error";
}

Change your input type to "submit": 将输入类型更改为“提交”:

<input name="submit" type="submit" value="Submit">

Then on your php file, I see you have a variable $info ... 然后在您的php文件上,我看到您有一个变量$info ...

mail ($to, $subject, $info, "From: " . $name . $email);

But I don't see that it's actually defined anywhere. 但是我看不到它实际上是在任何地方定义的。 Before your mail function, give $info a value. 在您的邮件功能之前,给$info一个值。

$info = "Hello World!";

Make sure to upload these files to a server - the php won't execute locally (unless you have a localhost running). 确保将这些文件上传到服务器-php不会在本地执行(除非您正在运行localhost)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM