PHPMailer 在邮件中嵌入图片
<无详细内容>
function embed_images(&$body)
{
// get all img tags
preg_match_all('/<img.*?>/', $body, $matches);
if (!isset($matches[0])) return;
// foreach tag, create the cid and embed image
$i = 1;
foreach ($matches[0] as $img)
{
// make cid
$id = 'img'.($i++);
// replace image web path with local path
preg_match('/src="(.*?)"/', $body, $m);
if (!isset($m[1])) continue;
$arr = parse_url($m[1]);
if (!isset($arr['host']) || !isset($arr['path']))continue;
// add
$this->AddEmbeddedImage('/home/username/'.$arr['host'].'/public'.$arr['path'], $id, 'attachment', 'base64', 'image/jpeg');
$body = str_replace($img, '<img alt="" src="cid:'.$id.'" style="border: none;" />', $body);
}
}
精彩图集
精彩文章






