473,383 Members | 1,716 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

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
Jul 17 '05 #1
3 6748
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.
Jul 17 '05 #2

"Pedro" <he****@hotpop.com> wrote in message
news:bm************@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
Jul 17 '05 #3
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.
Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Jonathan | last post by:
I want to save textarea contents to a mysql database with the paragraph breaks intact without having to type paragraph or break tags in HTML. How can I do that. So far, although it occurs naturally...
6
by: Mark Miller | last post by:
I have a scheduled job that uses different XSL templates to transform XML and save it to disk. I am having problems with the code below. The problem shows up on both my development machine (Windows...
0
by: Peter Rilling | last post by:
Although an ADODB question, I am using C#, so here I go. I am trying to use the ADODB Stream object to extract content from a body part of an MHTML formatted document. I can save the raw...
4
by: News | last post by:
Hi Everyone, The attached code creates client connections to websphere queue managers and then processes an inquiry against them. The program functions when it gets options from the command...
4
by: Rock | last post by:
Hello, I am going bananas trying to get text breaks and empty lines into this text which is sent in an email. I have tried "'s and \n and r\n\ but the text in the email still wraps and also I...
0
by: adamselearning | last post by:
I have HTML content defined in an external XML file: I am using code to identify when a <p> tag is present, so it is not treated as an XML node. I'm also using CDATA in some cases, and still...
6
by: Thomas Kowalski | last post by:
Hi, currently I am reading a huge (about 10-100 MB) text-file line by line using fstreams and getline. I wonder whether there is a faster way to read a file line by line (with std::string line)....
3
by: TonyJ | last post by:
Hello! I supposed to modify some text files. In the file(s) which consist of different section. In one section you might have Path = <Installation_path>. The program will then replace the text...
10
by: happyse27 | last post by:
Hi All, I got this apache errors(see section A1 and A2 below) when I used a html(see section b below) to activate acctman.pl(see section c below). Section D below is part of the configuration...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.