Wednesday, May 18, 2016

How to show line break from textarea in php mail

Intorduction:
Normally we just get the textarea message filed and put in our Email function, but when Email receive the textarea message filed show as continue without any New Line / line brack /
, so in this atrical i will describe you the simple code to get correct format for the textarea message filed.

PHP Function:  nl2br() 
full Function we use:  nl2br(htmlspecialchars()


Description:
string nl2br ( string $string [, bool $is_xhtml = true ] )
Returns string with '
' or '
' inserted before all newlines (\r\n, \n\r, \n and \r).

Parameters 
string:
    The input string.
is_xhtml:
    Whether to use XHTML compatible line breaks or not.

Sample Code:
$name = htmlspecialchars($_POST['name']);
$message = nl2br(htmlspecialchars($_POST['message']));
 

Example:





















 Output :
 The output will be same as you Enter in the textarea filed.

Dear Team,
Kindly let us know the book if its in stock.
Regards
ABC
+9221122

No comments:

Post a Comment