欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  php教程

PHPMailer 在邮件中嵌入图片

程序员文章站 2022-06-01 14:24:20
...
PHPMailer 在邮件中嵌入图片
function embed_images(&$body)
{
    // get all img tags
    preg_match_all('//', $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, '', $body); 
    }
}

以上就是PHPMailer 在邮件中嵌入图片的内容,更多相关内容请关注PHP中文网(www.php.cn)!