Search code examples
javascriptphphtmlmailto

Format mailto link so that PHP can cleanly interpret it


How do I format a mailto: protocol so that way PHP can interpret it in the following fashion:

//General PHP test:
print_r($_GET);

//Desired output:
Array
(
 [mailto] => [email protected]
 [subject] => Test Subject
 [body] => Placeholder body example.
 [bcc] => [email protected]
 [cc] => [email protected]
)

Currently I've got mailto:[email protected]&subject=The%20Subject&body=Some+test+text. though it gets interpreted as:

Array
(
 [mailto:test@example_com&subject=The%20Subject&body=Some+test+text_] => 
)

Solution

  • if you are willing to make a small change to the input string, instead of mailto:[email protected] you are willing to put an equals sign like [email protected] then the following code makes it easy:

    $querystr = "[email protected]&subject=The%20Subject&body=Some+test+text";
    $array = array();
    
    parse_str($querystr, $array);
    
    print_r($array);
    

    output is:

    Array ( [mailto] => [email protected] [subject] => The Subject [body] => Some test text )