View Full Version : <br /> in mailto
keyboard
11-02-2011, 09:37 PM
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
<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>
molendijk
11-02-2011, 10:32 PM
Should be \n, not<br>.
But I'm not a php-er.
===
Arie Molendijk.
bluewalrus
11-02-2011, 11:26 PM
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
keyboard
11-03-2011, 12:23 AM
<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)
bluewalrus
11-03-2011, 12:41 AM
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
$test = 'asdfa
asdf
asdf
zxcv';
echo urlencode(nl2br($test));
?>
keyboard
11-03-2011, 07:28 AM
I tried that
<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???
djr33
11-03-2011, 07:55 AM
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.
keyboard
11-06-2011, 06:54 AM
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
<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?
hawaiiwebdesign
11-06-2011, 09:38 PM
$test = <<<EOF
some content
woohooo
and now for a variable: ${somevar}
>>>;
return $test;
keyboard
11-06-2011, 10:12 PM
<?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
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.