AddEmbeddedImage()函数包含内嵌图像以及附加相同的图像作为附件

Sum*_*wal 3 html php email

我已将以下参数添加到PHPMailer对象.虽然我使用AddEmbeddedImage()函数嵌入了用于内联目的的图像,但它按预期工作,但另外附加相同的图像作为附件到电子邮件并在底部显示.

$msg = `<table><tr><td colspan="2"><img  src="cid:header_jpg" alt="www.example.in" width="770" height="4" border="0" /></td></tr></table>`;

$mail = new PHPMailer(true); //New instance, with exceptions enabled
$mail->IsSMTP(); // tell the class to use SMTP
$mail->SMTPAuth   = false;        // enable SMTP authentication
$mail->Port       = 25;           // set the SMTP server port
$mail->Host       = 'localhost';  // SMTP server
$mail->Username   = "";           // SMTP server username
$mail->Password   = "";           // SMTP server password

$mail->AddReplyTo($sender, $sender_name);

$mail->From       = $sender;
$mail->FromName   = $sender_name;

$mail->AddAddress($receiver);

$mail->Subject  = $subject;

//$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->WordWrap   = 80; // set word wrap

$mail->MsgHTML($msg);

$mail->IsHTML(true); // send as HTML
$mail->AddEmbeddedImage('./images/header.jpg', 'header_jpg');          
$mail->AddEmbeddedImage('./images/logo.jpg', 'logo_jpg');        
$mail->AddEmbeddedImage('./images/alert_icon.png', 'alert_icon_png', 'alert_icon.png');        
$mail->Send();
Run Code Online (Sandbox Code Playgroud)

请尽早提出建议......

小智 6

我对网络电子邮件嵌入图像存在同样的问题.我尝试了不同的方法并得到了这些结果:

发送html电子邮件到雅虎:

$mail->AddEmbeddedImage("some_picture.png", "my-attach", "some_picture.png", "base64", "image/png");

要么

$mail->AddEmbeddedImage("some_picture.png", "my-attach", "some_picture.png", "base64", "application/octet-stream");

要么

$mail->AddEmbeddedImage("some_picture.png", "my-attach", "some_picture.png");

相同的结果; 雅虎正确显示了嵌入的图像,但仍然附加了它!

使用hotmail,它正确嵌入了图像,没有添加附件.

最后,我想知道PHPMailer能够自动嵌入HTML电子邮件中的图像.在编写HTML电子邮件时,您必须将完整路径放在文件系统中.我最终忽略了AddEmbeddedImage并将图像源直接链接到网站上的位置.它在Hotmail和Yahoo中都运行正常,雅虎没有添加任何附件.

<img src="http://FULL_PATH-TO-IMAGE" alt="THIS IS THE IMAGE" />

不用说,除非用户点击"显示图像"按钮,否则电子邮件中嵌入的图像可能不会立即显示; 这一切都取决于他们的隐私和安全设置.

我希望这有帮助!