PHP 邮件程序不包含正文
我有这个表单
<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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要告诉它向您发送用户的电子邮件。
试试这个:
you need to tell it to send you the email of the user.
try this:
$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 themail
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 tomail
.您正在 $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