How to display image in message part in wp_mail function?

Abhee

I am trying to send mail when a post is published. For that I wrote code in my function.php file, the mail is correctly sending, but the featured image is not sent. I want to display the featured image attached to the post. Right now in mail the featured image is not displayed, but the link of fthe eatured image is displayed.

What can I do to achieve my task to display the featured image in the mail? I am attaching the code I have written in function.php file:

function mysendmail($post_id) {

$post = get_post($post_id);
$author = get_userdata($post->post_author);
$subject = "Post Published: ".$post->post_title."";

$message = "
      Hi ".$author->display_name.",

      Your post, \"".$post->post_title."\" has just been published.

      View post: ".get_permalink( $post_id )."

      Your Image: ".get_the_post_thumbnail( $post->ID )."

      Thanks"
      ;

   wp_mail($author->user_email, $subject, $message);
}
add_action('publish_post', 'mysendmail');
Rushi Vasani

To attach file through wp_mail function, you need to use $attachments parameter in it. In which you need to give absolute file path of attachment.

function mysendmail($post_id) {

$post = get_post($post_id);
$author = get_userdata($post->post_author);
$subject = "Post Published: ".$post->post_title."";


$attachments = get_attached_file( get_post_thumbnail_id( $post_id ));
$headers[] = '';


$message = "
      Hi ".$author->display_name.",

      Your post, \"".$post->post_title."\" has just been published.

      View post: ".get_permalink( $post_id )."

      Thanks"
      ;

   wp_mail($author->user_email, $subject, $message, $headers, $attachments);
}
add_action('publish_post', 'mysendmail');

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to use wp_mail() function in wordpress

How to display image sent from Laravel in email message

How to display an image as a message in an Alert Dialog box?

How to display specific part of image in square

How to send HTML form data to wp_mail function on wordpress?

Fabricjs: how to display only a part of image?

How to display a part of a big image?

How to display message in Qlabel from externally called Python function

How to not display part of an image that falls outside its div

How to send html format massage using wp_mail()?

wp_mail (Wordpress mail function) not sending to gmail or live.co.uk accounts

Function to display image

Why wp_mail() function returns 'false'?

How to display the message in the popup?

How to display an image in alert/message box in jsp

How to display the image from ajax success function?

How to send wp_mail with attachment (file-path in variable)

How to use the WordPress wp_mail(); function on an external PHP using Advanced Email Options settings e.g. WP-Mail-SMTP Plugin

Attaching a pdf with wp_mail function in wordpress

Wordpress wp_mail function error in template via ajax

How to fade part of an image

VueJS - Function to display image

Using range function to display a message

How to display part of the product image over div with gray background color?

How to display a success message

How to blur part of a image?

How to display loading message during the execution of my function?

How to display message in HTML Tag with PHP in a function

Doesn't send wp_mail() message with AJAX