我如何试用我的PHP代码来查看它是否有效? [英] How can I try my PHP code to see whether it works?
问题描述
我正在尝试制作一个基本的联系表单(使用HTML和PHP)。我通常将我的网站作为GitHub上的gh页面托管。然而,该表单在GitHub上不起作用,因为GitHub不允许PHP,因为GitHub Pages是一个静态站点托管服务,并且不支持服务器端代码,例如PHP,Ruby或Python。
我的问题是:我如何试用我的代码来查看它是否有效?
这是代码。
Html:
<!DOCTYPE html>
< html>
< head>
< title>< / title>
< / head>
< body>
< form action =send_form_email.phpmethod =POST>
< input type =textname =nameplaceholder =Full Name>
< input type =textname =mailplaceholder =您的电子邮件>
< input type =textname =subjectplaceholder =Subject>
< button type =submitname =submit>发送电子邮件< / button>
< / form>
< / body>
< / html>
PHP:
if(isset($ _ POST ['submit'])){
$ name = $ _POST ['name'];
$ subject = $ _POST ['subject'];
$ mailFrom = $ _POST ['mail'];
$ message = $ _POST ['message'];
$ mailTo =example@gmail.com;
$ headers =From:。$ mailFrom;
$ txt =您收到了来自。$ name。。\\\
\\\
的电子邮件。
mail($ mailTo,$ subject,$ txt,$ headers);
header(Location:index.php?mailsend);
}
PS。我知道我可以使用免费服务制作表单(例如 http://www.enformed.io 或 https://formspree.io )但我的问题是是否有办法(甚至是本地)检查我的代码如果我将它托管在适当的域名上,它就可以工作。
谢谢
您可以安装XAMPP并在本地运行您的页面。这个软件包里有PHP,Sendmail和Apache服务器。以及MySQL,如果你需要的话。
I'm trying to make a basic contact form (using HTML and PHP). I usually host my websites as gh-pages on GitHub. However, the form won't work on GitHub as GitHub doesn't allow PHP because "GitHub Pages is a static site hosting service and doesn't support server-side code such as, PHP, Ruby, or Python."
My question is: how can I try out my code to see if it works?
This is the code. Html:
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<form action="send_form_email.php" method="POST">
<input type="text" name="name" placeholder="Full Name">
<input type="text" name="mail" placeholder="Your e-mail">
<input type="text" name="subject" placeholder="Subject">
<textarea name="message" placeholder="Message"></textarea>
<button type="submit" name="submit">Send e-mail</button>
</form>
</body>
</html>
PHP:
if (isset($_POST['submit'])) {
$name = $_POST['name'];
$subject = $_POST['subject'];
$mailFrom = $_POST['mail'];
$message = $_POST['message'];
$mailTo = "example@gmail.com";
$headers = "From: ".$mailFrom;
$txt = "You have received an e-mail from ".$name.".\n\n".$message;
mail($mailTo, $subject, $txt, $headers);
header("Location: index.php?mailsend");
}
PS. I know that I can use free services to make forms (such as http://www.enformed.io or https://formspree.io) but my question is whether there is a way to (even locally) check whether my code would work if I hosted it on a proper domain.
Thank you
You can install XAMPP and run your pages locally. This package has PHP, Sendmail and Apache server in it. As well as MySQL if you need it.
这篇关于我如何试用我的PHP代码来查看它是否有效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!