SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Thread: Apply word wrap to PHP mail script - how to, my way not working.

  1. #1
    SitePoint Addict
    Join Date
    Aug 2008
    Posts
    237
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Apply word wrap to PHP mail script - how to, my way not working.

    I'm trying to add a word wrap function to this script.
    This is just a "dummy" practice script.

    For some reason it's not working.

    This is what I have.

    Code:
    $address = "test@test.com";
    $subject = "New Form Details Entered!";
    
    $message = "<b>Web Message:</b><br><br>";
    $message .= "<b>First Name:</b> ".$_POST['firstName']."<br>";
    $message .= "<b>Last Name:</b> ".$_POST['lastName']."<br>";
    $message .= "<b>Email:</b> ".$_POST['Email']."<br>";
    $message .= "<b>Phone Number:</b> ".$_POST['phoneNumber']."<br><br>";
    $message .= "<b>Comments/Message:</b><br> ".$_POST['comments']."<br>";
    
    $headers  = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    $headers .= 'From: '.$_POST['firstName']." ".$_POST['lastName'].'<test@test.com>' . "\r\n";
    
    $message = wordwrap($message, 70);
    mail($address, $subject, $message, $headers);
    
    ?>
    As of this point the text in the comment area goes to the end of the browser window.

    Any ideas how I can fix that?

    IC

  2. #2
    SitePoint Guru
    Join Date
    Jan 2005
    Location
    heaven
    Posts
    953
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you would have to specify <br> if you want it to break the line in the browser. If you view the source you'll see the line breaks. Thats because its rending using the \n, \r\n if your using windows, character.

    PHP Code:
     wordwrap($text20"<br />\n"); 
    Creativity knows no other restraint than the
    confines of a small mind.
    - Me
    Geekly Humor
    Oh baby! Check out the design patterns on that framework!

  3. #3
    SitePoint Addict
    Join Date
    Aug 2008
    Posts
    237
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by imaginethis View Post
    you would have to specify <br> if you want it to break the line in the browser. If you view the source you'll see the line breaks. Thats because its rending using the \n, \r\n if your using windows, character.

    PHP Code:
     wordwrap($text20"<br />\n"); 
    Thanks for the "fix" really appreciate your help.
    But how do I do this if I wanted to apply the word wrap only to the comments and not the entire message variable.

    The point only the comment variable contains the text area.

    Any ideas?

    Thanks again.

    IC

  4. #4
    SitePoint Guru
    Join Date
    Jan 2005
    Location
    heaven
    Posts
    953
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    apply wordwrap() to $_POST['comments']?
    Creativity knows no other restraint than the
    confines of a small mind.
    - Me
    Geekly Humor
    Oh baby! Check out the design patterns on that framework!

  5. #5
    SitePoint Addict
    Join Date
    Aug 2008
    Posts
    237
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just out of curiosity, when I get the mail, the word wrap works well but when I filled the text area and enter a line break or started a new paragraph, the message I received contained no line break.

    So if I get a very long message, it's hard to read because all the text are all jammed together.

    So is there a way you can script a mail so that it carries out user line breaks or new paragraph or is this the way PHP works in general?

    Thanks for your help.

    IC

  6. #6
    SitePoint Guru
    Join Date
    Jan 2005
    Location
    heaven
    Posts
    953
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can try nl2br to convert line breaks to <br>
    Creativity knows no other restraint than the
    confines of a small mind.
    - Me
    Geekly Humor
    Oh baby! Check out the design patterns on that framework!

  7. #7
    SitePoint Addict
    Join Date
    Aug 2008
    Posts
    237
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by imaginethis View Post
    You can try nl2br to convert line breaks to <br>
    Okay you just lost me, I should have mentioned, I'm very new to PHP and just getting my feet wet so please be patient if I asked you to elaborate further if you can.

    Thanks again.

    IC

  8. #8
    SitePoint Guru
    Join Date
    Jan 2005
    Location
    heaven
    Posts
    953
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    nl2br is a function that will replace the \n or \r\n to <br>. Just try it and you'll understand.
    [php
    echo nl2br("this is a \n line that has been \n broken up over \n 4 lines.");
    [/php]
    Creativity knows no other restraint than the
    confines of a small mind.
    - Me
    Geekly Humor
    Oh baby! Check out the design patterns on that framework!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •