0

issue is after I use the mail function it adds a return break that is not there. code is as follow:

    $lesujet = "testing ...";
    $letexts = "a bunch of text       
    there is a return break here
    another return break as you see";

    mail("myemail@gmail.com",$lesujet,$letexts,$headers);

this is what the email look like : a bunch of text

there is a return break here

another return break as you see

cppit
  • 4,478
  • 11
  • 43
  • 68

2 Answers2

2

Try using the function str_ireplace to remove the line break characters:

$letexts = str_ireplace(array("\r","\n"),array('',''),$letexts);
Phil Cross
  • 9,017
  • 12
  • 50
  • 84
  • isnt that going to remove all the breaks? that would mess up the paragraphs – cppit Aug 03 '12 at 17:57
  • 1
    if you want to keep paragraphs: $letexts = str_ireplace("\r\n\r\n","{paragraph}",$letexts); $letexts = str_ireplace(array("\r","\n"),array('',''),$letexts); $letexts = str_ireplace("{paragraph}","\r\n\r\n",$letexts); Just convert double linebreaks into a unique identifier (so you know where paragraphs are, remove all line breaks, then convert the unique identifiers (which identify actual paragraphs) back into paragraphs. Although I'm not sure this method is the best way. – Phil Cross Aug 03 '12 at 22:14
0

That's because when you initialize the strings in multiple lines it actually adds a \r\n to the string after each line, try instead:

$letexts = "a bunch of text "
. "there is a return break here "
. "another return break as you see ";

For multiline string init, check this SO thread for the discussion around the best practices of multiline strings.

Community
  • 1
  • 1
rvil
  • 136
  • 1
  • 4
  • thanks R Villa but the variable $letexts comes from the db. and the data comes from a form that users submit. I cant break it like that manually.any way to make it work in code not manually break the lines? – cppit Aug 02 '12 at 06:28
  • Ah, then I guess the answer from Phil Cross is the one you are looking. – rvil Aug 02 '12 at 15:32