Guys, Help!
I believe my problem is so simple but i just cant make it work. I want to email the contents of a flat file text file using a form in a php page. I can send the email but the contents of the text file doesnt appear in the email message. Hence, the email is blank.
Some notes:
There's no parse error.
All special characters have been escaped.
The text file is not write-protected.
Below is the code:
<?php // EMAIL TO A FRIEND SCRIPT
// Set the page title and include the HTML header.
$page_title = 'Register!';
include ('./header.inc');
// START FORM VALIDATION
if (isset($_POST['submit'])) { // Handle the form.
// Check for SENDER's name.
if (strlen($_POST['name1']) > 0) {
$name1 = TRUE;
} else {
$name1 = FALSE;
echo '<p>You forgot to enter your name!</p>';
}
// Check for SENDER'S email address.
if (strlen($_POST['email1']) > 0) {
$email1 = TRUE;
} else {
$email1 = FALSE;
echo '<p>You forgot to enter your email address!</p>';
}
// Check for RECEIPIENT's name.
if (strlen($_POST['name2']) > 0) {
$name2 = TRUE;
} else {
$name2 = FALSE;
echo '<p>You forgot to enter your friend\'s name!</p>';
}
// Check for RECEIPIENT's email address.
if (strlen($_POST['email2']) > 0) {
$email2 = TRUE;
} else {
$email2 = FALSE;
echo '<p>You forgot to enter your friend\'s email address!</p>';
}
if ($name1 && $email1 && $name2 && $email2) { // If everything's okay.
// END OF FORM VALIDATION.
// START OF GETTING ARTCLE CONTENTS
// define filename
$article_src = "article2.txt";
// open file
$article_file = file_get_contents($rticle_src);
// read the file
$article = trim ($article_file);
// END OF GETTING ARTCLE CONTENTS
// START OF SENDING EMAIL
// Send an email.
$body = $article;
$subject = 'Your Friend Wants You to Read This Article';
mail ($_POST['email2'], $subject, $body, 'From: [email]email@domain.com[/email]');
// END OF SENDING EMAIL
echo '<p>This article has been sent to your friend\'s email address. Thank You.</p>';
} else {
echo '<p>Please go back and try again.</p>';
}
} else { // Display the form.
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<fieldset><legend>Enter your information in the form below:</legend>
<p><b>Name:</b> <input type="text" name="name1" size="20" maxlength="40" /></p>
<p><b>Email Address:</b> <input type="text" name="email1" size="40" maxlength="60" /> </p>
<p><b>Friend's Name:</b> <input type="text" name="name2" size="20" maxlength="40" /></p>
<p><b>Friend's Email Address:</b> <input type="text" name="email2" size="40" maxlength="60" /> </p>
</fieldset>
<div align="center"><input type="submit" name="submit" value="Submit Information" /></div>
</form><!-- End of Form -->
<?php
}
include ('./footer.inc'); // Include the HTML footer.
?>