I am having one string which is of near about 100 lines which is similar to this
My name is John. rn I am a boy. rn I am so in so
Here the above string is coming from backed so when I send mail using PHP mail function it should output as below.
My name is John.
I am a boy.
I am so in so
But unfortunately it give this output to me.
My name is John. I am a boy. I am so in so
The method I am using is similar to this.
$header .= "MIME-Version: 1.0rn";
$header .= "Content-type:text/html;charset=UTF-8rn";
$msg = "Above Str";
mail(to@user, Subject, $msg, $header);
Can anyone help to do make this proper so.
4
Answers
You specified
Content-type: text/html
, so the body of your e-mail message is a HTML document. As such, just like when building a regular webpage, newlines themselves have no visible effect.Use either paragraphs (
<p>...</p>
) or<br>
to get the result you’re after.You can try using PHP’s nl2br() function to convert the line breaks in the string to HTML line breaks before sending the email:
This will convert the rn line breaks in the string to HTML line breaks
before sending the email.
This
is telling the client to render it as HTML, where line breaks aren’t rendered.
If you want it as HTML, you can try:
to convert line breaks to HTML
<br />
.If you want the clients to render it as text, not HTML, change the content type to
text/plain
:for this type of output, u need to just create a separate page and add all content that you want to send over the mail.
then
$msg = Load page;
then call or load your that page here and your code will start working try it