Dronealone
IS-IT--Management
I'm trying to generate a plain text email from a textarea on a webpage.
However, I cannot get newlines to appear in the email.
The code is as follows:
TEXTAREA:
<textarea name="email" cols="130" rows="15"><?php echo stripslashes($email); ?></textarea>
MAIL CODE:
[PLS SEE COMMENTS NEXT TO EACH LINE]
//$email = stripcslashes($email); //If I manually add the \n character in the textbox, they then appear in $email with \\n. I can use stripcslashes to get rid of the additional \. This makes the string identical to the manually assigned one below, but does not display newlines in the email - it shows the \n.
//$email = "this\nis\nan"; //If I assign the variable directly newlines are added
$headers .= "Content-Type: text/plain; charset=ISO-8859-1\r\n";
for ($i = 0; $i < count($recipient); $i++)
{
mail($recipient[$i], $subject, $email, $headers);
}
break;
So if I don't manually add the \n to the characters in the textbox, the email all displays on one line. If I add the \n, another \ is added. I can then strip the slash, however this just displays the \n in the email Finally if I manually assign the value to the variable equivalent to the last step, it works.
What I want is people to be able to type in the textbox, use the return key and this be reflected as newlines in the email....
I've been stuck for ages on this.....Please help.
Thanks!
However, I cannot get newlines to appear in the email.
The code is as follows:
TEXTAREA:
<textarea name="email" cols="130" rows="15"><?php echo stripslashes($email); ?></textarea>
MAIL CODE:
[PLS SEE COMMENTS NEXT TO EACH LINE]
//$email = stripcslashes($email); //If I manually add the \n character in the textbox, they then appear in $email with \\n. I can use stripcslashes to get rid of the additional \. This makes the string identical to the manually assigned one below, but does not display newlines in the email - it shows the \n.
//$email = "this\nis\nan"; //If I assign the variable directly newlines are added
$headers .= "Content-Type: text/plain; charset=ISO-8859-1\r\n";
for ($i = 0; $i < count($recipient); $i++)
{
mail($recipient[$i], $subject, $email, $headers);
}
break;
So if I don't manually add the \n to the characters in the textbox, the email all displays on one line. If I add the \n, another \ is added. I can then strip the slash, however this just displays the \n in the email Finally if I manually assign the value to the variable equivalent to the last step, it works.
What I want is people to be able to type in the textbox, use the return key and this be reflected as newlines in the email....
I've been stuck for ages on this.....Please help.
Thanks!