如何连接到wp_mail函数将链接的图像转换为嵌入式图像?

问题描述

我需要一种挂接到wp_mail函数的方法,以便将链接的图像转换为嵌入式嵌入图像。

我找到了这个Display inline image attachments with wp_mail,但是这些示例将相同的固定图像(或固定图像)附加到外发电子邮件中,即使您没有使用该图像也是如此。适用于徽标,但不适用于其他内容图像。

因此,我需要一种将电子邮件中的所有/所有链接图像都嵌入式嵌入的方法。

我有此代码,但是它不起作用。任何帮助将不胜感激。

add_filter('wp_mail','inline_images');
function inline_images($atts) {
    $body = $atts['message'];

    $atts['message'] = preg_replace_callback(
        // Regex for finding image sources
        '/<img(.*?)src=[\'|\"](.*?)[\'|\"](|.*?)>/',// Callback
        function($matches) use ($images) {
            // For rebuilding the <img> tag
            $beforeImageSRC = $matches[1];
            $afterImageSRC  = $matches[3];

            // Image source
            $imageSRC       = $matches[2];
            // Is this source a PHPMailer cid?
            if(preg_match('/^cid:/',$imageSRC)) {
                $fileCID    = preg_replace('/^cid:/','',$imageSRC);
                // Does the cid exist in our associative array?
                if(isset($images[$fileCID])) {
                    // Update image source if we have it listed in array
                    $imageSRC = $images[$fileCID];
                }
            }
        return '<img' . $beforeImageSRC . 'src="' . $imageSRC . '"' . $afterImageSRC . '>';
    },$body);

    return $atts['message'];
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)