SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2005
    Location
    Manc, UK
    Posts
    72
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    spacing between email sent with php

    This will be a very simple questionfor the experts Im new to php but I have a form and its sending fine but I need to put a space in btween each line Im presuming the spacing will go between each of the lines below

    Code:
    $body.='Wedding Date: '.$date."\n";
    $body.='Time Of Service: '.$time."\n";
    $body.='Brides Name: '.$bname."\n";
    $body.='Brides Phone: '.$bphone."\n";
    $body.='Grooms Name: '.$gname."\n";
    Thanks

  2. #2
    SitePoint Member
    Join Date
    Nov 2008
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If by 'space' you mean a blank line between lines in your email, then use two new line characters "\n" instead of one, like so:

    PHP Code:
    $body.='Wedding Date: '.$date."\n\n"

  3. #3
    SitePoint Enthusiast
    Join Date
    Nov 2005
    Location
    Manc, UK
    Posts
    72
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thats brilliant exactly wht I meant - thanks very much for taking the time to help - one more thing is it easy to print out something like
    ----------------------------
    underneath certain things to separate the form into sections so to speak?

    Thanks
    Rob

  4. #4
    SitePoint Member
    Join Date
    Nov 2008
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, you can just do something like:

    PHP Code:
    $body .= 'Wedding Date' "\n";
    $body .= '-------------' "\n";
    $body .= $date "\n\n"
    If you have many fields to format in this way I'd put the code into a function so you don't have to change multiple lines if you want to change the format of the email, such as:

    PHP Code:
    function formatEmailField($field$value) {
       return 
    $field "\n"
              
    '-------------' "\n" 
              
    $value "\n\n";


  5. #5
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,097
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    If you want the line to be always exactly as long as the text it's under you can use:

    PHP Code:
    function formatEmailField($field$value)

       return 
    $field."\n" 
              
    str_repeat('-'strlen($field))."\n"  
              
    $value."\n\n"

    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy


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
  •