0

I need to get a post thumbnail to show up in an email, but this doesnt work with just mailto: as i've tried it.

<a href="mailto:?subject=Anbefalt innlegg - <?php the_title(); ?>&body=Hei, jeg fant et innlegg som jeg tror du vil like. <img src='<?php echo wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); ?>'>">

This only gives me the url, and the img tag doesnt work. Any ideas how to make this work?

  • 1
    Actually, you can't. See this answer here – 99teko Aug 29 '16 at 10:56
  • Is there another way to do it? Or is it a totally lost cause? – jrnd.bjrkhg Aug 29 '16 at 11:00
  • Check my answer. – 99teko Aug 29 '16 at 11:20
1

The mailto protocol is fairly limited and does not support html in the body. Notably iOS supports some tags, but you cannot rely on that. The point is that mailto parses information from the browser to the user's email program. The more tags are allowed, the higher the security risk becomes. So, if you insist on sending the mail using the remote mailing program, you're stuck.

The alternative is using wp_mail. Users could still click on a link, but in stead of to their mailing program, the will be brought to a (popup) page where can send their message. There are many plugins that do this.

0

This is just a workaround by encoding HTML Characters.

<a href="mailto:?subject=Anbefalt innlegg - <?php the_title(); ?>&body=%3Cp%3EHei, jeg fant et innlegg som jeg tror du vil like. %3C%2Fp%3E%3Cimg%20src%3D%22<?php echo wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); ?>%22%20 %20%2F%3E">Write Email!</a>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.