Rawurlencode show’s ascii codes in emailto body and subject

Made this button that will share a post’s excerpt and title in WordPress via the visitors email client:

<a href="mailto:?subject=<?php echo rawurlencode()(get_the_title('','', false)) ?>&amp;body=<?php echo rawurlencode()(get_the_excerpt()) ?><?php the_permalink() ?>" title="Send a link to this post via email" rel="nofollow" target="_blank">Share this post via email</a>

It’s working fine for 99%. The only problem is that it show’s the ascii codes from the post’s body and title.
So for example, i get in the email body to see ‘ &hellip;‘ instead of […]

Read More

How can I solve this minor problem?

Related posts

Leave a Reply

1 comment

  1. Basically, you will probably need to decode your html entities that are returned by get_the_title and get_the_excerpt via calls like

    html_entity_decode(get_the_title())
    

    So, in your case, you would have to wrap your calls to rawurlencode around html_entity_decode:

    <a href="mailto:?subject=<?php echo rawurlencode(html_entity_decode(get_the_title('','',   false)))?> ...
    

    But beware that, depending on your usage of html_entites_decode if your excerpt contains quotes or doublequotes your markup may get messed up and it will not work, so you would need to filter these. Read the doc for more info:

    http://www.php.net/html_entity_decode

    (Edit: You could pass the ENT_NOQUOTES parameter to html_entity_decode for excluding quotes from the conversion; but if your titles or excerpts contain quotes those will still will be displayed encoded in your email.)

    Furthermore, if your title or excerpts contain user generated content you might open up a security hole when you reverse the encoded entities (e.g. for XSS injections). So I would suggest finding another way to send the email (e.g. some kind of recommendation plugin).