gpt4 book ai didi

wordpress - 如何在wp_mail 函数中的消息部分显示图像?

转载 作者:行者123 更新时间:2023-12-03 08:01:44 29 4
gpt4 key购买 nike

我正在尝试在帖子发布时发送邮件。为此,我在我的 function.php 文件中编写了代码,邮件正确发送,但特色图片未发送。我想显示贴在帖子上的特色图片。现在在邮件中不显示特色图片,但显示特色图片的链接。

我该怎么做才能完成在邮件中显示特色图片的任务?我附上我在 function.php 文件中编写的代码:

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');

最佳答案

要通过wp_mail 函数附加文件,您需要在其中使用$attachments 参数。其中你需要给出附件的绝对文件路径。

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');

关于wordpress - 如何在wp_mail 函数中的消息部分显示图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45938349/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com