PHP 邮件程序不包含正文

发布于 2024-12-04 21:20:20 字数 1407 浏览 0 评论 0原文

我有这个表单

<form method="POST" action="mailer.php">
    <div id="email"><input type="email" name="email" class="email" placeholder="[email protected]"></div>
</form>

和这个 PHP

<?php

$email = $_POST['email'];
$to = "[email protected]";
$subject = "ADD THIS EMAIL ADDRESS TO THE MAILING LIST";
$body = "\n\n";
$url = 'http://10.0.1.1/~ewiuf';
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
    echo '<script> alert("PLEASE ENTER A VALID EMAIL ADDRESS") </script>';
    echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL=' . $url . '">';
} else {
    if (mail($to, $subject, $body)) {
        echo '<script> alert("THANK YOU FOR SUBSCRIBING TO THE NEWSLETTER") </script>';
        echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL=' . $url . '">';
    } else {
        echo '<script> alert("THERE WAS AN UNEXPECTED ERROR. PLEASE TRY AGAIN LATER") </script>';
        echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL=' . $url . '">';
    }
}
?>

为什么表单的内容(应该是电子邮件地址)没有包含在脚本发送的电子邮件正文中?该脚本发送、验证,但用户在表单中输入的电子邮件地址没有发送给我。请帮忙,谢谢。

I have this form

<form method="POST" action="mailer.php">
    <div id="email"><input type="email" name="email" class="email" placeholder="[email protected]"></div>
</form>

And this PHP

<?php

$email = $_POST['email'];
$to = "[email protected]";
$subject = "ADD THIS EMAIL ADDRESS TO THE MAILING LIST";
$body = "\n\n";
$url = 'http://10.0.1.1/~ewiuf';
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
    echo '<script> alert("PLEASE ENTER A VALID EMAIL ADDRESS") </script>';
    echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL=' . $url . '">';
} else {
    if (mail($to, $subject, $body)) {
        echo '<script> alert("THANK YOU FOR SUBSCRIBING TO THE NEWSLETTER") </script>';
        echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL=' . $url . '">';
    } else {
        echo '<script> alert("THERE WAS AN UNEXPECTED ERROR. PLEASE TRY AGAIN LATER") </script>';
        echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL=' . $url . '">';
    }
}
?>

Why is the contents of the form, which should be email addresses, not being included in the body of the emails which the script sends? The script sends, verifies, but the email address that the user enters into the form is not sent to me. Please Help, thanks.

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

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

发布评论

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

评论(3

荒人说梦 2024-12-11 21:20:20

您需要告诉它向您发送用户的电子邮件。
试试这个:

<?php
$email = $_POST['email'];
$to = "[email protected]";
$subject = "ADD THIS EMAIL ADDRESS TO THE MAILING LIST";
$body = "User Email: ".$email;
$url = 'http://10.0.1.1/~ewiuf';
if(!filter_var($email, FILTER_VALIDATE_EMAIL))
{
echo '<script> alert("PLEASE ENTER A VALID EMAIL ADDRESS") </script>';
echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
}
else
{
if (mail($to, $subject, $body)) {
echo '<script> alert("THANK YOU FOR SUBSCRIBING TO THE NEWSLETTER") </script>';
echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
 } else {
echo '<script> alert("THERE WAS AN UNEXPECTED ERROR. PLEASE TRY AGAIN LATER") </script>';
echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
 }
}
?>

you need to tell it to send you the email of the user.
try this:

<?php
$email = $_POST['email'];
$to = "[email protected]";
$subject = "ADD THIS EMAIL ADDRESS TO THE MAILING LIST";
$body = "User Email: ".$email;
$url = 'http://10.0.1.1/~ewiuf';
if(!filter_var($email, FILTER_VALIDATE_EMAIL))
{
echo '<script> alert("PLEASE ENTER A VALID EMAIL ADDRESS") </script>';
echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
}
else
{
if (mail($to, $subject, $body)) {
echo '<script> alert("THANK YOU FOR SUBSCRIBING TO THE NEWSLETTER") </script>';
echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
 } else {
echo '<script> alert("THERE WAS AN UNEXPECTED ERROR. PLEASE TRY AGAIN LATER") </script>';
echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
 }
}
?>
弥枳 2024-12-11 21:20:20

$body = "\n\n"; 是您设置或更改 $body 变量的唯一位置,它是您作为正文发送的变量(第三个参数)到 mail 功能。

就您而言,我假设您只想将电子邮件地址放入正文中,因此您应该使用 $body = $email; ,或者只使用 $email code> 而不是 $body 作为 mail 的第三个参数。

$body = "\n\n"; is the only place you set or change the $body variable, which is the variable you send as the body (third parameter) to the mail function.

In your case, I assume you only want to put the e-mail address in the body, so you should use $body = $email; for that, or just use $email instead of $body as the third parameter to mail.

紫轩蝶泪 2024-12-11 21:20:20

您正在 $body 中发送“\n\n”。
如果我答对了你的问题,你可能想在其中添加 $email,例如
$body = "\n\n" + $email

希望有帮助

You are sending "\n\n" in $body.
If i get your question right, you might want to add $email to it, like
$body = "\n\n" + $email

hope that helps

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