Wordpress 如何连接到wp_mail函数以将链接图像转换为内联附加图像?
我需要一种连接到wp_mail函数的方法,以便将链接的图像转换为内嵌的图像 我发现了这一点,但这些示例将相同的固定图像(或固定图像)附加到每封发出的电子邮件,即使您没有使用该图像。适用于徽标,但不适用于其他内容图像 因此,我需要一种方法,使电子邮件中的任何/所有链接图像都内嵌 我有这个代码,但它不工作。任何帮助都将不胜感激Wordpress 如何连接到wp_mail函数以将链接图像转换为内联附加图像?,wordpress,wp-mail,Wordpress,Wp Mail,我需要一种连接到wp_mail函数的方法,以便将链接的图像转换为内嵌的图像 我发现了这一点,但这些示例将相同的固定图像(或固定图像)附加到每封发出的电子邮件,即使您没有使用该图像。适用于徽标,但不适用于其他内容图像 因此,我需要一种方法,使电子邮件中的任何/所有链接图像都内嵌 我有这个代码,但它不工作。任何帮助都将不胜感激 add_filter('wp_mail','inline_images'); function inline_images($atts) { $body = $att
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'];
}
add_filter('wp_-mail','inline_-images');
函数内联图像($atts){
$body=$atts['message'];
$atts['message']=预替换回调(
//用于查找图像源的正则表达式
'//',
//回拨
函数($matches)使用($images){
//重建",;
},
$body);
返回$atts['message'];
}