When text string is mailed, extra line breaks are introducd

This is a discussion on When text string is mailed, extra line breaks are introducd within the PHP Language forums, part of the PHP Programming Forums category; Hi all, I have the following message string: $message = <<<EOT Personal Information: Name: {$_POST["name"]} ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 10-16-2003
Joshua Beall
 
Posts: n/a
Default When text string is mailed, extra line breaks are introducd

Hi all,

I have the following message string:

$message = <<<EOT
Personal Information:
Name: {$_POST["name"]}
Address: {$_POST["address"]}

EOT;

Now, when I echo this to the browser, (and view the source), it is exactly
what you would expect. Three lines of information. However, if I use
mail() or the PEAR Mail class to send $message via email, I get an extra
line break at the end of every line. What in the world would cause this?
Any ideas?

-Josh


Reply With Quote
  #2 (permalink)  
Old 10-17-2003
Pedro
 
Posts: n/a
Default Re: When text string is mailed, extra line breaks are introducd

Joshua Beall wrote:
> I have the following message string:
>
> $message = <<<EOT
> Personal Information:
> Name: {$_POST["name"]}
> Address: {$_POST["address"]}
>
> EOT;


Try this instead:
$message = "Personal Information\n Name: {$_POST[name]}\n Address: {$_POST[address]}";


> Now, when I echo this to the browser, (and view the source), it is exactly
> what you would expect. Three lines of information. However, if I use
> mail() or the PEAR Mail class to send $message via email, I get an extra
> line break at the end of every line. What in the world would cause this?
> Any ideas?


I'm betting on a few "\r" in the middle of the message being
converted to "\n".


HTH


--
I have a spam filter working.
To mail me include "urkxvq" (with or without the quotes)
in the subject line, or your mail will be ruthlessly discarded.
Reply With Quote
  #3 (permalink)  
Old 10-17-2003
Joshua Beall
 
Posts: n/a
Default Re: When text string is mailed, extra line breaks are introducd


"Pedro" <hexkid@hotpop.com> wrote in message
news:bmn5ef$om59s$1@ID-203069.news.uni-berlin.de...
> Try this instead:
> $message = "Personal Information\n Name: {$_POST[name]}\n Address:

{$_POST[address]}";

That is the workaround that I have been using. I was just hoping there
another way.

> I'm betting on a few "\r" in the middle of the message being
> converted to "\n".


Ah, of course, that would make perfect sense. I bet every line is getting
\r\n at the end of it when PHP stores the string. I suppose I could just do
a string replace to strip out all the \r characters. Oh well.

Thanks!

-Josh


Reply With Quote
  #4 (permalink)  
Old 10-17-2003
Pedro
 
Posts: n/a
Default Re: When text string is mailed, extra line breaks are introducd

Joshua Beall wrote:
> Ah, of course, that would make perfect sense. I bet every line is getting
> \r\n at the end of it when PHP stores the string. I suppose I could just do
> a string replace to strip out all the \r characters. Oh well.


Removing all "\r"s might not be such a good idea ... some OS's use it as
the line break character. The ones I know of are:

Un*x \n
DOS/Win \r\n
Macintosh \r

Expecting only these and assuming the user will not type the character
with code zero, I do:

<?php
$input = $_POST['textarea'];
$input = str_replace("\r\n", "\x00", $input);
$input = str_replace("\r", "\x00", $input);
$input = str_replace("\x00", "\n", $input);
?>



--
I have a spam filter working.
To mail me include "urkxvq" (with or without the quotes)
in the subject line, or your mail will be ruthlessly discarded.
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 06:28 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0