On a product page I have added a Contact Form 7 form that lets a visitor request more information about the product via email.
Now I want to embed the featured image (of the productpage the mail was sent from), in the email.
I'm using the plugin Contact Form 7 - Dynamic Text Extension to use hidden fields in the contact form and some custom code that I found that retrieves the image. (Original source)
// Retrieve product featured imgae.
add_shortcode( 'product_img', 'dcwd_product_img_from_product_id' );
function dcwd_product_img_from_product_id() {
$product_id = get_the_ID();
$product_img = 'unknown';
if ( is_int( $product_id ) ) {
$product_img = get_the_post_thumbnail_url( $product_id, 'thumbnail' );
}
return html_entity_decode( $product_img );
}
This code works, it gives the URL, but in the email it doesn't show the image when I put it in between tags.
I also tried:
$product_img = get_the_post_thumbnail( $product_id, 'thumbnail' );
This just displays the raw <img />
html code.
There is a checkmark in the Contact Form 7 email settings that says: "Use HTML content type", this makes no difference.