Home >php教程 >PHP源码 >PHPMailer 在邮件中嵌入图片

PHPMailer 在邮件中嵌入图片

PHP中文网
PHP中文网Original
2016-05-25 17:14:471710browse

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)!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn