Reputation: 31
I'm trying to create a mailto link using PHP. Basically my function gets the body text from database and then creates the html tag like this:
<a href="mailto:?subject=sample&body=sometexthere">send</a>
well, the problem is that my body text may contain non standard characters, like accents and so, so i need to encode the body text before output it; but i don't know how to do it because when my mail client opens (Windows Live Mail) it displays wrong characters for the body.
How can i solve this? what is the right encoding to use unicode text into the body?
many thanks in advance,
Upvotes: 2
Views: 6186
Reputation: 786
I encountered this same problem; my first intuition was to use urlencode()
but that did not work.
Try using:
rawurlencode()
In general this function is more reliable when working across different systems; a major reason is that urlencode
converts spaces to +
which will be left as-is by most mail clients.
So for example:
echo '<a href="mailto:?subject=sample&body='.rawurlencode($your_text_variable).'">send</a>';
This worked for me.
Upvotes: 0
Reputation: 485
Be aware that there seems to be an issue with Outlook if there are non-Ascii characters in sometexthere
.
See this post: mailto special characters
Upvotes: 0
Reputation: 4963
You have to implement those replacements
http://www.ietf.org/rfc/rfc2368
Upvotes: 0