TransWikia.com

Sending current featured image to email

WordPress Development Asked by HM Dadou on January 26, 2021

I am trying to send the featured image with other details by email to admin.
Everything is working well except that the featured image is sent to email only when the post is edited from admin. If edited from frontend all the details are sent except the image.

I don’t know why.

Here’s the code:

// send email on creation or update of a campaign
 add_action( 'save_post', 'campaign_updated_send_email' );
 function campaign_updated_send_email( $post_id ) { 
    //check post type is product
    $ptype = get_post_type( $post_id );
    if ( $ptype === 'product') {
    //verify campaign/product is not a revision 
    if ( !wp_is_post_revision( $post_id ) ) { 
         $post_title = get_the_title( $post_id ); 
         $post_url = get_permalink( $post_id ); 
         
    //get the post status
    $mypoststatus = get_post_status( $post_id );
    // get the campaign image
    $image = wp_get_attachment_image_src( get_post_thumbnail_id( $loop->post->ID ), 'single-post-thumbnail' );




         $subject = '[Campaign updated:]'.$post_title; 
         $message = "A campaign has been updated2:nn";


        $message = "<a href='". $post_url. "'><img src=".$image[0]." width=250></a>nn";
         $message .= "<br><a href='". $post_url. "'><h3>" .$post_title. "</h3></a><h3>Current Status:<U>".$mypoststatus."</U></h3>nn"; 
        $headers = array('Content-Type: text/html; charset=UTF-8');
         //send email to admin 
         wp_mail( get_option( 'admin_email' ), $subject, $message, $headers); 
   } 
}
} 

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP