Jetpack电子邮件共享按钮,用于在发送的电子邮件中包含图像

时间:2013-05-31 作者:adriana

我正在通过修改sharedaddy.php 现在,我已经花了数小时试图将附在帖子上的图像包含在电子邮件中。

我尝试在下面的函数中添加以下两个代码,但没有在发送的电子邮件中显示帖子中的图像:

$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 );
}

1 个回复
SO网友:GhostToast

wp_mail 不支持丰富的格式,因此您不能只将图像嵌入到正文中。但是,它确实支持附件。如果您阅读了有关该函数的内容,您将看到它有一个附件参数。请尝试将附件挂在此处:

http://codex.wordpress.org/Function_Reference/wp_mail

$attachments (字符串或数组)(可选)要附加的文件:单个文件名、文件名数组或多个文件名的换行分隔字符串列表。(高级)默认值:空

编辑:因此,如果您可以计算出要引用的图像的附件idwp_mail 函数看起来更像这样:

// check if featured image, use it if so
if(has_post_thumbnail()){
    $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;
    }
}

wp_mail( 
    $data[\'target\'], 
    $data[\'post\']->post_title, 
    $content, 
    \'\',  
    wp_get_attachment_url($attachment_id)
);

结束

相关推荐