SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Wizard Defender1's Avatar
    Join Date
    Apr 2001
    Location
    My Computer
    Posts
    2,808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Textareas and line breaks in php

    Hi. I want to make a mailing script where an admin will go to a page, type in the message, and it'll mail all the users that have signed up for it (stored in database) with what the person enters in the comments textarea.
    now, i've noticed with other scripts that when a user hits enter in a textarea, and that is intern stored in a mysql db, it doesn't put in a break.
    How would i make it so there is a break so the entire mail isn't one long line?
    Defender's Designs
    I'm Getting Married!

    Not-so-patiently awaiting Harry Potter Book 7 *sigh*

  2. #2
    SitePoint Guru
    Join Date
    Sep 2001
    Location
    Vancouver
    Posts
    809
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Either a \n or simply a <br> tag should do it.

  3. #3
    Grumpy Mole Man Skunk's Avatar
    Join Date
    Jan 2001
    Location
    Lawrence, Kansas
    Posts
    2,067
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Breaks ARE stored in mySQL (it treats newline as it would any other character and stores is "as is") but because it stores it as a newline when you view the information in the field with something like phpMyAdmin you won't see the break, as HTML ignores newlines and only puts breaks if there is a <br> tag. The solution is to use nl2br() when you extract the information from the database before displaying it. Alternatively if you are displaying the list of addresses in a textarea you won't need to use nl2br() as text in a textarea is displayed with newlines intact.

  4. #4
    SitePoint Wizard Defender1's Avatar
    Join Date
    Apr 2001
    Location
    My Computer
    Posts
    2,808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well, this is going into a non-html email.
    would i have to manually enter a \n for every return i want to do in the text area?
    Defender's Designs
    I'm Getting Married!

    Not-so-patiently awaiting Harry Potter Book 7 *sigh*

  5. #5
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No you don't have to, jsut show us your code. Also what email client are you using? Becuase you should technically do:

    $msg = str_replace("\r\n", "\n", $msg);

    This stops the massive one line thing ...

    -Peter

  6. #6
    SitePoint Addict lveale's Avatar
    Join Date
    Jun 2001
    Location
    Dublin
    Posts
    221
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    WORDWRAP

    Established at this stage that anytime you hit enter within the textfield, there should be a return in the mail, but you should also use the wordwrap function.

  7. #7
    SitePoint Wizard Defender1's Avatar
    Join Date
    Apr 2001
    Location
    My Computer
    Posts
    2,808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    here's my code:
    PHP Code:
    <? // mail_users.php
    $db_connect mysql_connect(***edited***);
    $db_name "dbname";

    if (!
    $send_email) {
    ?>
    <form action="<?=$PHP_SELF?>" method="post">
    <font size="2" face="Arial">
    Enter the subject of this mail:&nbsp;&nbsp
    <input type="text" size="20" name="subject"><br>
    <br>
    Enter the message to be mailed to all users:<br>
    <textarea cols="40" rows="10" name="message_body"></textarea><br>
    <input type="submit" name="send_email" value="Send Mail">
    <input type="reset" value="Clear">
    </form>
    <?
    include ('join_footer.php');

    } else {
    $sql "SELECT * from mailing_list";
    $do_query mysql_db_query($db_name$sql$db_connect) or die (mysql_error());

    echo 
    "Please wait while the mails are processed...\n";

    while (
    $results mysql_fetch_array($do_query))
    {
     
    mail("$results[email]""$subject""$message_body""From: 3dartisan Mailer");
    }

    echo 
    "<br><br>Mails sent succesfully!\n";
    ?>
    <br><br>You can either <a href="<?=$PHP_SELF?>">Send another mail</a> or <a href="/index.php">return home</a>.
    <?
    include ('join_footer.php');
    }
    ?>
    Defender's Designs
    I'm Getting Married!

    Not-so-patiently awaiting Harry Potter Book 7 *sigh*

  8. #8
    SitePoint Wizard Defender1's Avatar
    Join Date
    Apr 2001
    Location
    My Computer
    Posts
    2,808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    and what does it matter what email client I use. this is going to be used to SEND mail to people who have subscribed to a mailing list.
    Defender's Designs
    I'm Getting Married!

    Not-so-patiently awaiting Harry Potter Book 7 *sigh*

  9. #9
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you view email in outlook there are no line breaks, but outlook express and many others show them.

  10. #10
    SitePoint Wizard Defender1's Avatar
    Join Date
    Apr 2001
    Location
    My Computer
    Posts
    2,808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    so, is there some universal way to make the line breaks?
    Defender's Designs
    I'm Getting Married!

    Not-so-patiently awaiting Harry Potter Book 7 *sigh*

  11. #11
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Use the suggestions I said...


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
  •