I am changing the message for the email sent by modifying the sharedaddy.php file and have now spent hours trying to include the image attached to the post on the email.

I tried adding the following two codes within the function below and had no luck displaying the images from the post in the email sent:

$content .=  wp_get_attachment_url($post->ID); 


$content .=  wp_get_attachment_image( $post->ID, 'medium' );


function sharing_email_send_post( $data ) {
    $content  = sprintf( __( 'Someone you know visited my website Living Healthy With Chocolate, http://livinghealthywithchocolate.com and thinks you may be interested in the following recipe:'."\n\n", 'jetpack' ), $data['name'], $data['source'] );
    $content .= $data['post']->post_title."\n";
    $content .= get_permalink( $data['post']->ID )."\n";
    wp_mail( $data['target'], ' '.$data['post']->post_title, $content );

wp_mail does not support rich formatting, so you can't just embed the image in the body. It does, however, support attachments. If you read about the function, you'll see it has a parameter for attachments. Try hooking your attachment there instead:


$attachments (string or array) (optional) Files to attach: a single filename, an array of filenames, or a newline-delimited string list of multiple filenames. (advanced) Default: Empty

Edit: So if you can figure out the attachment id of the image you want to reference, the wp_mail function will look more like this:

// check if featured image, use it if so
    $attachment_id = get_post_thumbnail_id();
} else {
    // otherwise use first post attachment
    $attachments = get_children( array(
        'post_parent'    => get_the_ID(),
        'post_type'      => 'attachment',
        'numberposts'    => 1, 
    foreach($attachments as $attachment_id_key => $attachment){
        $attachment_id = $attachment_id_key;

  • thanks GhostToast. I am sorry but I am not very good at this and I am not sure how to call the image. Can you give me an example? I want to include the featured image from the post on the email sent. – adriana May 31 '13 at 20:23
  • Updated answer to provide example. – GhostToast May 31 '13 at 20:31
  • is it possible to automatically include either the first image of the post or the featured image on the email sent? The emails are sending recipes to the recipient and a picture of the recipe is important. Here's is the website: livinghealthywithchocolate.com – adriana May 31 '13 at 20:38
  • Use get_post_thumbnail_id() to get the featured image ID. – GhostToast May 31 '13 at 20:40
  • ok so I changed it to wp_mail( $data['target'], ' '.$data['post']->post_title, $content, '', get_post_thumbnail_id() ); and it's not working. – adriana May 31 '13 at 20:54

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.