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