无法将表单提交页面重定向到php

时间:2014-03-13 05:27:48

标签: php html

我无法将表单提交页面重定向到php。当我点击提交时它显示我的PHP页面,我正在寻找代码,表格可以保存在特定位置&点击subit后,用户需要获得Thank You message&邮件应该发送给我自己

我的代码如下:

HTML

<html>
<title>
Test
</title>
<body>
<form method="post" action="test2.php"> onsubmit="return"
<center>
<font color="FFFFFF">From: <br><input name="email"type="text"></font>
</center>
<br>
<center>
<font color="FFFFFF">SSL Request:<br><textarea name="message" rows="3" cols="30"></textarea></font>
</center>
<br>
<center>
<input type="submit" value="Submit Request!">
</center>
</form>
<br>
This is test form
</body>
</html>

PHP:

<?PHP
$email = $_POST["emailaddress"];
$to = "abc@yahoo.com";
$subject = "New Email Address for Mailing List";
$headers = "From: $email\n";
$message = "A visitor to your site has sent the following email address to be added to your mailing list.\n

Email Address: $email";
$user = "$email";
$usersubject = "Thank You";
$userheaders = "From: you@youremailaddress.com\n";
$usermessage = "Thank you for subscribing to our mailing list.";
mail($to,$subject,$message,$headers);
mail($user,$usersubject,$usermessage,$userheaders);
?>

1 个答案:

答案 0 :(得分:0)

我认为你正在访问php文件而不在web服务器上运行。

要运行PHP代码,我们需要一个支持PHP的Web服务器,如XAMPP(免费服务器集合)或WAMP。安装服务器后,将您的php文件放入htdocs文件夹,然后通过Web服务器链接访问您的文件。

如果没有服务器,则无法直接运行PHP代码。

本教程可能对您有所帮助。 https://www.udemy.com/blog/xampp-tutorial/