Encoding mailto: Subject Lines

I was working on a very simple “email this article as a recommendation” feature, where the user would click a link to open their email client with a pre-populated subject and email body. The link looks like this:
<a href=”mailto:?subject=SUBJECT_TEX…


This content originally appeared on foobartel.com :: Stream and was authored by foobartel.com :: Stream

I was working on a very simple “email this article as a recommendation” feature, where the user would click a link to open their email client with a pre-populated subject and email body. The link looks like this:

<a href="mailto:?subject=SUBJECT_TEXT&body=BODY_TEXT"

The issue I ran into showed up when the article title contained special characters and especially an ampersand (&), since that would cut off the subject line, because it would signal the beginning of the next paramater. This feature is for a Kirby site and I tried a few different PHP encodings to get around this problem. One of the obvious things to try was to urlencode() the string. Since urlencode() replaces the spaces with a “+” sign, it wasn’t the right choice. Eventually the solution was to use PHP’s rawurlencode() for the subject text, which uses “%20” for spaces which are later invisible in the subject line.


This content originally appeared on foobartel.com :: Stream and was authored by foobartel.com :: Stream


Print Share Comment Cite Upload Translate Updates
APA

foobartel.com :: Stream | Sciencx (2019-12-04T23:00:00+00:00) Encoding mailto: Subject Lines. Retrieved from https://www.scien.cx/2019/12/04/encoding-mailto-subject-lines-2/

MLA
" » Encoding mailto: Subject Lines." foobartel.com :: Stream | Sciencx - Wednesday December 4, 2019, https://www.scien.cx/2019/12/04/encoding-mailto-subject-lines-2/
HARVARD
foobartel.com :: Stream | Sciencx Wednesday December 4, 2019 » Encoding mailto: Subject Lines., viewed ,<https://www.scien.cx/2019/12/04/encoding-mailto-subject-lines-2/>
VANCOUVER
foobartel.com :: Stream | Sciencx - » Encoding mailto: Subject Lines. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2019/12/04/encoding-mailto-subject-lines-2/
CHICAGO
" » Encoding mailto: Subject Lines." foobartel.com :: Stream | Sciencx - Accessed . https://www.scien.cx/2019/12/04/encoding-mailto-subject-lines-2/
IEEE
" » Encoding mailto: Subject Lines." foobartel.com :: Stream | Sciencx [Online]. Available: https://www.scien.cx/2019/12/04/encoding-mailto-subject-lines-2/. [Accessed: ]
rf:citation
» Encoding mailto: Subject Lines | foobartel.com :: Stream | Sciencx | https://www.scien.cx/2019/12/04/encoding-mailto-subject-lines-2/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.