php - 在邮件正文 phpmailer 类中添加嵌入图像

标签 php html phpmailer

我试图在邮件正文中嵌入图片,但最终以附件形式出现

    $mailer->Subject = APP_NAME . " - " . $name . " send you and Ad : " . $row['name'];
    $mailer->IsHTML(true);
    $mailer->AddEmbeddedImage('../images/namDiams.png', 'logoimg', 'namDimes.png'); 

    //footer
    $footer = "Regards<br/><br/>";
    $footer .= '<table style="width: 95%">';
    $footer .= '<tr>';
    $footer .= '<td>';
    $footer .= "<strong><span style='font-size: 15px'>NamDimes Team</span></strong><br/>
                    NamDimes<br/>
                    Contact Number: " . APP_CONTACT . "<br/>
                    Email: " . APP_EMAIL . "<br/>
                    Website: " . APP_WEBSITE . "<br/>";
    $footer .= '</td>';
    $footer .= '<td style="text-align:right">';
    $footer .= '<img src=\"cid:logoimg\" />';
    $footer .= '</td>';
    $footer .= '</tr>';
    $footer .= '</table>';

    $mailer->Body = $body . $footer;
    $mailer->AltBody="This is text only alternative body.";
    $mailer->AddAttachment('../' . $row['image_path'], $row['name'] . ".jpg");

我已经设置了其他所有内容,包括地址,邮件已发送,我想嵌入正文的 Logo 图像作为附件附加,有人知道为什么吗?

最佳答案

不要使用 $mailer->AddEmbeddedImage , 而是直接添加

<img src="http://.../images/namDiams.png" />相反。

邮件长度应该更轻......而且它有效。

编辑

我不知道它是否对你有帮助,但这里有一个小错误:

$mailer->AddEmbeddedImage('../images/namDiams.png', 'logoimg', 'namDimes.png');

应该是

$mailer->AddEmbeddedImage('../images/namDiams.png', 'logoimg', 'namDiames.png');//the last param the second 'a' was missing...

另一个话题here

关于php - 在邮件正文 phpmailer 类中添加嵌入图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15518703/

相关文章:

PHP 将推文插入 mysql

php - 在 MysQL 或 PHP 中将记录从一列拆分为两列

html - Chrome 43 中文本偶尔会溢出到 div 之外

html - 编写带有图像的 html 电子邮件

html - 使用 phpmailer 发送整个 html 页面

php - 如何使用 phpmailer 并从 ckeditor 以 html 格式发送邮件

PHPmailer 无法从 MySQL 获取电子邮件收件人

php - 对表 1 返回 ID 的查询,表 2 包含评级,如何通过在 Just 1 查询中加入表 1 和表 2 来获得 SUM 评级?

php - 波兰字符 utf8 不显示正确

php - 日期 T 和 Z 格式