在mailto链接中避免将空格更改为iPhone中的加号

I have a php code that renders a mailto: link

echo "<a href='mailto:?'". http_build_query([
   'subject' => 'this is a subject',
   'body' => 'this is a body',
])."'>Link</a>";

In my desktop browser, when I clicked the link the browser goes to GMail and the mail body is rendered nicely.

But when I use my iPhone, the compose app shows "+" instead of spaces.

How can I avoid this?

This is standard URI code. Spaces are expected to be transformed to something else than a space. The most common character is the '+', some people prefer to use %20.

When you decode a URI, it automatically replaces the '+' back to spaces. So your code is probably missing that one call...

You probably want to look at this function:

http://us1.php.net/manual/en/function.urldecode.php


According to scrowler comment, try to put %20 instead of spaces to see what happens:

echo "<a href='mailto:?'". http_build_query([
   'subject' => 'this%20is%20a%20subject',
   'body' => 'this%20is%20a%20body',
])."'>Link</a>";