Results 1 to 10 of 10

Thread: <br /> in mailto

  1. #1
    Join Date
    Mar 2011
    Posts
    1,898
    Thanks
    59
    Thanked 105 Times in 103 Posts
    Blog Entries
    4

    Default <br /> in mailto

    Hey everyone,

    How can you put a line break into a mailto???
    Like if you wanted a message to go over a couple of lines?

    Here's my code

    HTML Code:
    <a href="mailto:email@email.com?subject=Itunes Account
    &body=
    <?php
    echo "BALANCE";
    
    echo "name1 ";
    echo '$';
    echo $row3['balance']; 
    echo "name2";
    echo '$';
    echo $row2['balance']; 
    ?>
    ">Send me an email</a>

  2. #2
    Join Date
    Sep 2007
    Location
    The Netherlands
    Posts
    1,859
    Thanks
    49
    Thanked 260 Times in 252 Posts
    Blog Entries
    56

    Default

    Should be \n, not<br>.
    But I'm not a php-er.
    ===
    Arie Molendijk.

  3. #3
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    Why not use a form and send the message using PHP's mail function? Once using that apply the html header, and use nl2br.

    http://php.net/manual/en/function.mail.php
    http://us2.php.net/manual/en/function.nl2br.php
    Corrections to my coding/thoughts welcome.

  4. #4
    Join Date
    Mar 2011
    Posts
    1,898
    Thanks
    59
    Thanked 105 Times in 103 Posts
    Blog Entries
    4

    Default

    PHP Code:
    <a href="mailto:email@email.com?subject=Itunes Account
    &body=
    <?php
    echo "BALANCE";

    echo 
    "name1 ";
    echo 
    '$';
    echo 
    $row3['balance']; 
    echo 
    "\n";
    echo 
    "name2";
    echo 
    '$';
    echo 
    $row2['balance']; 
    ?>
    ">Send me an email</a>

    I tried that but it still dosen't work.
    I can't use mail() as I am going to run this script on localhost(WAMP)

  5. #5
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    You'll need to convert them encode them to be passed through the url and encode them to be converted from \n to <br />. This also assumes the users mail client supports HTML. Something like

    PHP Code:
    <?php
    $test 
    'asdfa
    asdf
    asdf
    zxcv'
    ;
    echo 
    urlencode(nl2br($test));
    ?>
    Corrections to my coding/thoughts welcome.

  6. #6
    Join Date
    Mar 2011
    Posts
    1,898
    Thanks
    59
    Thanked 105 Times in 103 Posts
    Blog Entries
    4

    Default

    I tried that

    PHP Code:
    <a href="mailto:email@email.com?subject=Subject
    &body=
    <?php 
    $test 
    'asdfa 
    asdf 
    asdf 
    zxcv'

    echo 
    urlencode(nl2br($test)); 
    ?> 


    ">Send me an email</a>
    and it printed this

    Asdfa+<Br+/>
    Asdf+<Br+/>
    Asdf+<Br+/>
    Zxcv


    Am I doing it right???

  7. #7
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    You'll actually probably need the following to make sure it doesn't conflict with the HTML:
    echo htmlspecialchars(urlencode(nl2br($test)));

    But, more or less, yes, that's correct. It's not important what it prints on the page (well, it is, but only indirectly). Instead, you need to see how it works after you click the link-- those + symbols should probably become spaces, if everything works right.

    Realistically, the entire approach is a problem: not that many people use email links to send messages (many use gmail, hotmail, yahoo or something else on the web, so they don't have a default mail program to open automatically), so that won't help, and if anything it will make it harder for those who don't use it to cut/paste the email to write you a message.

    If you're just doing this for fun, that's fine, but otherwise I'd recommend either just using the email address (and they can type the message if needed), or the best idea is to use PHP to send the message as part of your website.

    If you do choose to use this format, I say at least ignore the body and just add a subject. That might (sometimes) be helpful, but the rest just won't work enough that it's worth your time to solve this.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  8. #8
    Join Date
    Mar 2011
    Posts
    1,898
    Thanks
    59
    Thanked 105 Times in 103 Posts
    Blog Entries
    4

    Default

    Quote Originally Posted by djr33 View Post
    Realistically, the entire approach is a problem: not that many people use email links to send messages (many use gmail, hotmail, yahoo or something else on the web, so they don't have a default mail program to open automatically), so that won't help, and if anything it will make it harder for those who don't use it to cut/paste the email to write you a message.

    If you're just doing this for fun, that's fine, but otherwise I'd recommend either just using the email address (and they can type the message if needed), or the best idea is to use PHP to send the message as part of your website.
    Thanks for your opinion djr33. I'm using this at home(wamp) so it won't be avalible to the public so thats not a problem.




    I tried this

    PHP Code:
    <a href="mailto:email@email.com?subject=Subject 
    &body= 
    <?php  
    $test 
    'asdfa  
    asdf  
    asdf  
    zxcv'
    ;  
    echo 
    htmlspecialchars(urlencode(nl2br($test))); 
    ?>  
    ">Send me an email</a>
    And now it's printing this

    Asdfa++<Br+/>
    Asdf++<Br+/>
    Asdf++<Br+/>
    Zxcv

    Any help?

  9. #9
    Join Date
    Nov 2011
    Location
    Seattle, WA & Big Island, HI
    Posts
    5
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    $test = <<<EOF
    some content
    woohooo
    and now for a variable: ${somevar}

    >>>;

    return $test;

  10. #10
    Join Date
    Mar 2011
    Posts
    1,898
    Thanks
    59
    Thanked 105 Times in 103 Posts
    Blog Entries
    4

    Default

    PHP Code:
    <?php
    }
    $somevar "yodog";
    ?>

    <a href="mailto:email@email.com?subject=Subject 
    &body= 
    <?php  

    $test 
    = <<<EOF
    some content
    woohooo
    and now for a variable: 
    ${somevar}

    >>>;

    return 
    $test
    ?>  

    ">Send me an email</a>

    It dosen't work

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
  •