简体   繁体   中英

Hide HTML tags from textarea

I'm working on email system in my project(PHP/MySql). In my email forward form I have a text area where I'm including the following data as gmail and yahoo is doing.

---------- Forwarded message ----------
From: <testfrom@yahoo.com>
Date: Mon, Jan 9, 2014 at 10:48 PM
Subject: Order Confirmation
To: testto@gmail.com

I'm using echo "\\n"; for line breaking in the above data. When I forward this data in email, It send as one row instead of sending as the above format. Can anyone help me how to send it in exactly the same format.

Note : I try to user <br> for line breaking but in that case it send <br> also in email.

Use nl2br for your message. This will convert all \\n to <br/> .

Something like:

$message = $_POST['message'];
mail('email@example.com', 'subject', nl2br($message));

My only assumption that new line symbols are present in an email, you just don't see them.

For example, if you create php script:

<?php
echo "hello \n world";

and open it in a browser, you will not be able to view new line, because browser doesn't handle \\n symbol as line break.

You will only see line breaks if you view the source of the page (by hitting CTRL+U in Chrome and Firefox, don't know about other browsers).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM