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…

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.


Print Share Comment Cite Upload Translate
APA
foobartel.com :: Stream | Sciencx (2024-03-28T22:24:23+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 2024-03-28T22:24:23+00:00,<https://www.scien.cx/2019/12/04/encoding-mailto-subject-lines-2/>
VANCOUVER
foobartel.com :: Stream | Sciencx - » Encoding mailto: Subject Lines. [Internet]. [Accessed 2024-03-28T22:24:23+00:00]. Available from: https://www.scien.cx/2019/12/04/encoding-mailto-subject-lines-2/
CHICAGO
" » Encoding mailto: Subject Lines." foobartel.com :: Stream | Sciencx - Accessed 2024-03-28T22:24:23+00:00. 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: 2024-03-28T22:24:23+00:00]
rf:citation
» Encoding mailto: Subject Lines | foobartel.com :: Stream | Sciencx | https://www.scien.cx/2019/12/04/encoding-mailto-subject-lines-2/ | 2024-03-28T22:24:23+00:00
https://github.com/addpipe/simple-recorderjs-demo