Jump to content

[SOLVED] Line breaks not working in mail


Andy17

Recommended Posts

Hey,

 

 

When I send out an e-mail, my line breaks are displayed as "\r\n" in the e-mails instead of being spaces. I am saving the messages in my MySQL database and there it says <br /> for every line break. I'm very tired so it's easier to show an example:

 

The following

 

This <br /> is a test <br /> for phpfreaks!

 

would look the same in my MySQL database, but like this in the sent e-mail:

 

 This
\r\nis a test
\r\nfor phpfreaks!

 

Here is the relevant parts of my code:

 

<?php

// Some variables here that are not important in regard to my problem

$headers  = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "from: hqdesigns.net<[email protected]>";

$comment = mysql_real_escape_string(nl2br($_POST['newcomment_field']));

mail($email, $subject, $comment, $headers);

?>

 

Any help is much appreciated!

Link to comment
https://forums.phpfreaks.com/topic/166718-solved-line-breaks-not-working-in-mail/
Share on other sites

I'm not sure I understand your problem? Could you elaborate it? :)

 

You know what <br /> does on an HTML page. I want it to do that in the e-mails I send as well, but instead it just writes out "\r\n" as text instead of actually making a line break as <br /> normally does.

 

I heard it depends on which mail you are using. Some web host mail doesn't accept html..

 

It might work in hotmail !

 

My e-mail does allow this. I have actually had this problem before and I remember having to make a .htaccess file to turn off magicquotes or something. I did this again, but without luck this time.

Just some information from phpinfo() (I believe the magic quotes are the problem somehow):

 

 

Directive / Local Value / Master Value

magic_quotes_gpc Off On

magic_quotes_runtime Off Off

magic_quotes_sybase Off Off

 

 

My .htaccess file contains the following:

 

php_flag magic_quotes_gpc Off

 

 

Thank you in advance for any help.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.