php - 当我发送电子邮件 / swiftmailer 时图像不显示
问题描述
我目前正在使用 Swiftmailer 发送我的电子邮件。一切正常,它正在发送电子邮件,但是电子邮件没有显示我输入的徽标。这是代码:
require_once 'vendor/autoload.php';
require_once 'config/constants.php';
// Create the Transport
$transport = (new Swift_SmtpTransport('smtp.gmail.com', 465, 'ssl'))
->setUsername(EMAIL)
->setPassword(PASSWORD);
// Create the Mailer using your created Transport
$mailer = new Swift_Mailer($transport);
function sendVerificationEmail($userEmail, $token){
global $mailer;
$body = '<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Verify Email</title>
</head>
<body>
<div class="not-verified-container">
<img src="logo.svg" class="mazaw-logo-not-verified">
<div class="container-without-logo">
<div class="not-verified-texts">
<h2>Account Verification</h2>
</div>
</div>
</div>
</body>
</html>';
// Create a message
$message = (new Swift_Message('Account Verification'))
->setFrom(EMAIL)
->setTo($userEmail)
->setBody($body, 'text/html');
// Send the message
$result = $mailer->send($message);
}
如果有人可以看看我做错了什么,我将非常感激。谢谢!
解决方案
嵌入应该可以正常工作
<?php
$message = new Swift_Message('Your subject');
$message->setBody(
'<html>' .
' <body>' .
' <img src="' . $message->embed(Swift_Image::fromPath('image.png')) . '" />' .
' </body>' .
'</html>',
'text/html'
);
?>
推荐阅读
- ethereum - 如何使用 waffle 和 ethers.js 测试应付/外部方法
- python - 根据时间Python聚合列表中的分类值
- mysql - mysql中的外连接不提供结果
- javascript - 如何使用 Reflect.getMetadata 检查异步/承诺
- python - 蟒蛇虫?我做错了什么?
- jmeter - 是否可以更改 JSR223 后处理器中的事务控制器响应时间?
- python - 在 linux 操作系统上安装 mtcnn 时出错。在 python 3.6.5 和最新的 pip 版本 21.0.1 上运行
- usb - 使用不同的供应商和产品 ID 使 USB 设备可见
- firebase - 如何使用 http 请求将 Arduino sim808 模块数据发送到 Firebase?
- javascript - redux-saga 工作流程中的生成器函数理解,yield