When text string is mailed, extra line breaks are introducd

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Joshua Beall

    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


  • Pedro

    #2
    Re: When text string is mailed, extra line breaks are introducd

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

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

    [color=blue]
    > 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?[/color]

    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.

    Comment

    • Joshua Beall

      #3
      Re: When text string is mailed, extra line breaks are introducd


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

      That is the workaround that I have been using. I was just hoping there
      another way.
      [color=blue]
      > I'm betting on a few "\r" in the middle of the message being
      > converted to "\n".[/color]

      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


      Comment

      • Pedro

        #4
        Re: When text string is mailed, extra line breaks are introducd

        Joshua Beall wrote:[color=blue]
        > 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.[/color]

        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("\x 00", "\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.

        Comment

        Working...