SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    HI silver trophy Silverado4x4's Avatar
    Join Date
    Jan 2001
    Location
    USA
    Posts
    953
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Simple problem from a newbie

    How do I get line breaks in the e-mail sent? It won't send line breaks even if I put \n in it!

    <form method="get" action="<?php echo $PHP_SELF?>">
    Friend's Name: <input type="text" name="recipname" size="10">
    Friend's E-Mail: <input type="text" name="recipemail" size="10">
    Starter: <input type="text" name="starter" size="10">
    <input type="submit" name="submit" value="Submit!">
    </form>
    <?php

    echo "<html><body>";

    $recipient .= "$recipemail";

    $subject = "$starter";

    $message .= "$starter \n\n";
    $message .= "What is this? FAQS below.\n";

    $headers .= "From: Your Friend <webmaster@jokes-central.com>\n";
    $headers .= "X-Sender: <webmaster@jokes-central.com>\n";
    $headers .= "X-Mailer: PHP\n"; // mailer
    $headers .= "Return-Path: <webmaster@jokes-central.com>\n"; // Return path for errors

    $headers .= "Content-Type: text/html; charset=iso-8859-1\n";

    mail($recipient, $subject, $message, $headers);

    if ($submit) {
    echo "Thank you. Your message is being processed.";
    }

    ?>
    http://www.jokes-central.com/php/send2.php

  2. #2
    SitePoint Evangelist ucahg's Avatar
    Join Date
    Apr 2001
    Location
    Sarnia, Ontario, Canada
    Posts
    434
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm not sure about the line breaks but you should have the whole email code only if it's submit, correct? Like this:

    PHP Code:
    <form method="get" action="<?php echo $PHP_SELF?>"> 
    Friend's Name: <input type="text" name="recipname" size="10"> 
    Friend's E-Mail: <input type="text" name="recipemail" size="10"> 
    Starter: <input type="text" name="starter" size="10"> 
    <input type="submit" name="submit" value="Submit!"> 
    </form> 
    <?php 

    if ($submit) {

     echo 
    "<html><body>"

     
    $recipient .= "$recipemail"

     
    $subject "$starter"

     
    $message .= "$starter \n\n"
     
    $message .= "What is this? FAQS below.\n"

     
    $headers .= "From: Your Friend <webmaster@jokes-central.com>\n"
     
    $headers .= "X-Sender: <webmaster@jokes-central.com>\n"
     
    $headers .= "X-Mailer: PHP\n"// mailer 
     
    $headers .= "Return-Path: <webmaster@jokes-central.com>\n"// Return path for errors 

     
    $headers .= "Content-Type: text/html; charset=iso-8859-\n"

     
    mail($recipient$subject$message$headers); 

     echo 
    "Thank you. Your message is being processed."


    ?>
    Love it? Hate it? Helpful? Useless?
    Use the rate button to let me know what you think of my post!

  3. #3
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    I just tried out your form. The message is being sent with a Content-Type: text/html header, which means that the content of your message is being treated as a Web page. As we all know, line breaks do not show on Web pages -- you need to use <br> tags instead.

    Since there is no actual HTML content in the message that is sent, you should probably just change the content type to text/plain (or leave the header out entirely).
    Kevin Yank
    CTO, sitepoint.com
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Baby’s got back—a hard back, that is: The Ultimate CSS Reference

  4. #4
    HI silver trophy Silverado4x4's Avatar
    Join Date
    Jan 2001
    Location
    USA
    Posts
    953
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, thanks for the help. I think it was because of the format of the e-mail (HTML).


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
  •