php - AddEmbeddedImage() 函数嵌入内联图像以及附加与附件相同的图像

标签 php html 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();

请尽早提出建议...

最佳答案

我在使用网络电子邮件嵌入图像时遇到了同样的问题。我尝试了不同的方法并得到了这些结果:

向雅虎发送 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 中都能正常工作,并且在 Yahoo 中没有添加任何附件。

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

不用说,除非用户单击“显示图像”按钮,否则电子邮件中嵌入的图像可能不会立即显示;这完全取决于他们的隐私和安全设置。

希望对您有所帮助!

关于php - AddEmbeddedImage() 函数嵌入内联图像以及附加与附件相同的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18445525/

相关文章:

PHPMailer 不会使用 SSL 发送,但 Outlook 会

php - 我怎样才能让 PHP mail() 工作?需要帮助配置 MTA

html - 菜单项略微倾斜?

html - 根据兄弟宽度确定div的宽度

html - Bootstrap UL 与元素符号

email - 通过 CMD 控制台发送邮件

php - 使用登录调用未定义的函数 mysql_query()

PHP 将查询结果分组为嵌套关联数组

php - 如何从 MySQL 大表中删除列

php - 使用 javascript 和 jquery 动态包含一个 php 文件