PHP 联系表单编辑

发布于 2024-08-14 04:44:23 字数 582 浏览 3 评论 0原文

我不是 PHP 专业人士,刚刚开始,想知道您是否可以帮助我。

我正在尝试获取此联系表格,然后通过电子邮件向我说明姓名和类似的消息。

姓名: 弗雷德·博客 消息:消息,消息。

但是当我尝试时,我得到的只是消息,我似乎无法在任何地方插入名称变量。

这是代码

<?php 
$name = $_REQUEST['name'] ;
$email = $_REQUEST['email'] ;
$message = $_REQUEST['message'] ;
$subject = $_REQUEST['subject'] ;

mail( "[email protected]", "Name: $name", "$subject", $message, "From: $email" );
header( "Location:contact.php" );
?>

Im not a pro at PHP, just starting actually and was wondering if you could help me.

Im trying to get this contact form to email me stating the Persons Name and the message like this.

Name: Fred Blogs
Message: Message, Message.

But when I try all I get is the message, I cant seem to insert the name variable anywhere.

This is the code

<?php 
$name = $_REQUEST['name'] ;
$email = $_REQUEST['email'] ;
$message = $_REQUEST['message'] ;
$subject = $_REQUEST['subject'] ;

mail( "[email protected]", "Name: $name", "$subject", $message, "From: $email" );
header( "Location:contact.php" );
?>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

走野 2024-08-21 04:44:23

您的参数有点混乱:

mail( "[email protected]", $subject, "Name: $name\nMessage: $message", "From: $email" );

此外,您不应该在不验证电子邮件地址的情况下执行 "From: $email" - 这将使您的脚本处于发送垃圾邮件的状态。

You've got the arguments mixed up a little:

mail( "[email protected]", $subject, "Name: $name\nMessage: $message", "From: $email" );

Additionally you shouldn't do "From: $email" without validating the email address - this will leave your script open to sending out spam.

手心的海 2024-08-21 04:44:23

您向 mail() 函数。尝试这样的事情:

<?php 
ob_start();
$name = $_POST['name'] ;
$email = filter_input(INPUT_POST, 'email', FILTER_SANITIZE_EMAIL);
$message = $_POST['message'] ;
$subject = strtr($_POST['subject'],array(':' => ' ', "\r" => ' ', "\n" => ' '));

$message = "Name: {$name}\r\nmessage: {$message}";
mail("[email protected]", $subject, $message, "From: {$email}");
header("Location: contact.php", true, 302);
ob_end_clean();
die;
?>

You are passing too many parameters to the mail() function. Try something like this:

<?php 
ob_start();
$name = $_POST['name'] ;
$email = filter_input(INPUT_POST, 'email', FILTER_SANITIZE_EMAIL);
$message = $_POST['message'] ;
$subject = strtr($_POST['subject'],array(':' => ' ', "\r" => ' ', "\n" => ' '));

$message = "Name: {$name}\r\nmessage: {$message}";
mail("[email protected]", $subject, $message, "From: {$email}");
header("Location: contact.php", true, 302);
ob_end_clean();
die;
?>
梦晓ヶ微光ヅ倾城 2024-08-21 04:44:23

看一下 mail() 的手册:

mail("[email protected]", "Name: $name", $message, "From: $email");

但无论如何,我强烈建议您不要依赖 PHP 的 mail() 函数,因为它的返回值并不表明邮件是否确实已发送。使用 phpmailer 进行邮件发送。

最美好的祝愿,
法比安

Take a look at the manual for mail():

mail("[email protected]", "Name: $name", $message, "From: $email");

But anyways, I strongly suggest you don't rely on PHP's mail()-function as its return value does not indicate if a mail really has been sent. Use phpmailer for mailing instead.

Best wishes,
Fabian

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文