对于php来说,我是一个完整的新手,我有以下的php,它会向我发回消息'并向用户发送自动回复,并将其重定向到“谢谢你”。页。我遇到的问题是它不会返回他们在表单上填写的用户名,任何想法?
<?php
$youremail = "ally.baird81@gmail.com"; //this is where the email will be sent to
@extract($_POST);$name = filter_var($name, FILTER_SANITIZE_STRING);
$message = filter_var($message, FILTER_SANITIZE_STRING);
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
if (mail($youremail, 'Message from website.', $message, "From: Krew Kut Hair<$email>")) {
$autoreply = "Thank you for enquiring at Krew Kut Hair, we will be in contact shortly";
$subject = "Thank you for your enquiry!";
mail($email, $subject, $autoreply, "From: Krew Kut Hair<$email>");
}
} else {
echo "Please enter a valid email address";
}
header("Location: thanks.html");
答案 0 :(得分:1)
如果您输入名为&#34; name&#34;像:
<input type="text" name="name" value="" />
检查它是否包含数据,例如:
echo 'The value of name is ['.$name.']';
如果它包含数据,您可以在邮件中使用$name
变量。如果不是HTML格式可能有问题。
<?php
$youremail = "ally.baird81@gmail.com"; //this is where the email will be sent to
@extract($_POST);$name = filter_var($name, FILTER_SANITIZE_STRING);
$message = filter_var($message, FILTER_SANITIZE_STRING);
$content = "<strong>Name:<strong><br />".$name."<br />";
$content .= "<strong>Message:<strong><br />".$message."<br />";
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
if (mail($youremail, 'Message from website.<br />', $content, "From: Krew Kut Hair<$email>")) {
$autoreply = "Hi ".$name.". Thank you for enquiring at Krew Kut Hair, we will be in contact shortly";
$subject = "Thank you for your enquiry!";
mail($email, $subject, $autoreply, "From: Krew Kut Hair<$email>");
}
} else {
echo "Please enter a valid email address";
}
header("Location: thanks.html");
同时阅读有关您问题的评论。我强烈建议您使用其他方法,而不是使用extract()
。
答案 1 :(得分:1)
假设名称位于其中一个表单字段中,您应该能够检索它。正如Barmar所说 - 你所要做的就是在身体或信息的某个地方使用它。如果你不在某个地方回应它,怎么能告诉你名字丢失了。 试试这个:
$autoreply = "Thank you ".$name." for ...
如果名称仍然“缺失” - 您可以尝试查看所有的帖子变量:
echo "<PRE>Post Vars\n"; print_r($_POST);