gpt4 book ai didi

php联系表格干净的代码

转载 作者:行者123 更新时间:2023-12-04 14:48:59 25 4
gpt4 key购买 nike

尝试用 php 制作我自己的联系表。有没有更好/更清洁的方法来解决这个问题?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1 /DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<title>Contact Form Practice</title>


</head>

<body>


<form method="POST" action="mailer.php">
Name:
<br>
<input type="text" name="name" size="19"><br>
<br>
Your Email Adress:
<br>
<input type="text" name="email" size="19"><br>
<br>
Message:
<br>
<textarea rows="9" name="message" cols="30"></textarea>
<br>
<br>
<input type="submit" value="Submit" name="submit">
</form>



</body>
</html>

----------------php----------------

<?php
if(isset($_POST['submit'])) {

$to = "mail@cheapramen.com";
$subject = "Contact";
$name_field = $_POST['name'];
$email_field = $_POST['email'];
$message = $_POST['message'];

$body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message";

echo "Data has been submitted to $to!";
mail($to, $subject, $body);

} else {

echo "4! OH! 4!";

}
?>

最佳答案

代码似乎是正确的,但我强烈建议添加一些数据验证。您需要确保所有必填字段都填写了有效信息。出于安全/可读性目的,还请务必编码/去除任何 HTML、JS 等。

最后,您还应该考虑使用 CAPTCHA 来防范垃圾邮件。我有一个运行与此类似代码的旧网站,过去每天收到超过 500 封垃圾邮件!

关于php联系表格干净的代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1898218/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com