龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > web编程 > php编程 >

PHPMailer 在邮件中嵌入图片

时间:2014-07-22 14:52来源: 作者: 点击:
分享到:
<无详细内容>
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); 
    }
}
精彩图集

赞助商链接