一尘不染

邮寄前如何在PHP中检查用户输入?

php

我有一个简单的PHP邮件程序脚本,该脚本从通过POST提交的表单中获取值并将其邮寄给我:

<?php
$to = "me@example.com";

$name = $_POST['name'];
$message = $_POST['message'];
$email = $_POST['email'];

$body  =  "Person $name submitted a message: $message";
$subject = "A message has been submitted";

$headers = 'From: ' . $email;

mail($to, $subject, $body, $headers);

header("Location: http://example.com/thanks");
?>

如何清除输入内容?


阅读 243

收藏
2020-05-26

共1个答案

一尘不染

用清理发布变量filter_var()

这里的例子。喜欢:

echo filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);
2020-05-26