开发者

PHP mailer does not include body

开发者 https://www.devze.com 2023-04-05 09:42 出处:网络
I have this form <form method=\"POST\" action=\"mailer.php\"> <div id=\"email\"><input type=\"email\" name=\"email\" class=\"email\" placeholder=\"example@example.com\"></div>

I have this form

<form method="POST" action="mailer.php">
    <div id="email"><input type="email" name="email" class="email" placeholder="example@example.com"></div>
</form>

And this PHP

<?php

$email = $_POST['email'];
$to = "test@test.com";
$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("THE开发者_JAVA技巧RE 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.


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

<?php
$email = $_POST['email'];
$to = "test@test.com";
$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.'">';
 }
}
?>


$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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消