Support

Account

Home Forums General Issues add file field or image field to attachment wp_mail

Solved

add file field or image field to attachment wp_mail

  • Is there any way to add the file field and/or image field to wp_mail attachment?

    i’m using this right now:

    function my_project_updated_send_email( $post_id ) {
    
    	// If this is just a revision, don't send the email.
    	if ( wp_is_post_revision( $post_id ) )
    		return;
    
    	$post_title = get_the_title( $post_id );
    	$post_url = get_permalink( $post_id );
    	$subject = 'A post has been updated';
    
    	$message = "A post has been updated on your website:\n\n";
    	$message .= $post_title . ": " . $post_url;
    
    	// Send email to admin.
    	wp_mail( 'email@example.com', $subject, $message );
    }
    add_action( 'save_post_cr3ativconference', 'my_project_updated_send_email' );
  • Hi @rudtek

    You should be able to get the path to the file by using the get_attached_file() function like this:

    $image_path = get_attached_file(get_field('image_field_name', $post_id, false));

    After that, you can add it to the wp_mail() attachment. This page should give you more idea about it: https://developer.wordpress.org/reference/functions/wp_mail/#div-comment-345.

    I hope this helps 🙂

  • Great Thanks!!!!! SO FAST TOO!

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.