PHP mailer does not include body
NickName:user852974 Ask DateTime:2011-09-18T07:33:19

PHP mailer does not include body

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.

Copyright Notice:Content Author:「user852974」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/7458540/php-mailer-does-not-include-body

Answers
Michael Madsen 2011-09-17T23:37:52

$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.\n\nIn 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.",


Ameer 2011-09-17T23:37:26

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


More about “PHP mailer does not include body” related questions

PHP mailer does not include body

I have this form &lt;form method="POST" action="mailer.php"&gt; &lt;div id="email"&gt;&lt;input type="email" name="email" class="email" placeholder="exam

Show Detail

PHP Mailer Could not load language file and Email Body Empty

Hi I am working with PHP mailer , Without doing any code changes when i send an email Now , the Email Body is empty . I debug the code and found in the mailer object that [ErrorInfo] =&gt; Could...

Show Detail

Sending <a> tag in body of email with Swift Mailer

I am new to Swift Mailer and would like to include a link in the body of the HTML message linking back to my home page however, the PHP script does not run when I include the anchor tag in the mess...

Show Detail

how to include PHP script as body of email

I have a php script that makes some MySQL queries that just writes some HTML (with the dynamic data) to a page. What I want to do is send an email with this HTML as the body. Lets say that the HTML

Show Detail

Php mailer body is empty

Iam using PHP mailer to send an Email the message sent but email body is Empty here is my code foreach($results as $result) { $email = $result['email']; $body = 'Hello'.$result['us

Show Detail

PHP Mailer - foreach in message body

I want to included results using foreach inside the body of an email message. PHP Mailer seems to just cut off the message when I add the foreach statement. Any ideas on how to include multiple re...

Show Detail

PHP Mailer Class issue :Message body empty

When i try to send email using PHPMailer class I get this error : Mailer Error: Message body empty : &lt;?php include("class.phpmailer.php"); $mail = new PHPMailer(); $mail-&gt;IsSMT...

Show Detail

How to include PHP variables in SwiftMailer body

First of all, I can send emails perfectly fine with Swift Mailer. However, I want to include PHP variables into the body of the email. This is what I've tried: $link = "hi"; $message-&gt;setBo...

Show Detail

PHP mailer not working with client gmail id

I am new in php i have a problem with my php mailer when i set $Host = 'ssl://smtp.googlemail.com'; $Username = 'my gamil id'; $Password = 'my gmail password'; $Port = 465; Php mailer working fi

Show Detail

php mailer Mailer Error: Language string failed to load: connect_host?

I keep getting this error.. below is my code: &lt;?php ini_set("include_path", "phpmailer/"); require 'phpmailer/class.phpmailer.php'; $mailer = new PHPMailer(); $mailer-&gt;IsSMTP()

Show Detail