发送电子邮件/ 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'
);    
?>
,

您需要在电子邮件中包含徽标图像作为附件。不知道在Swiftmailer中是如何做到的,但是当我用Google搜索它时,有很多示例,包括StackOverflow此处的示例。

Swiftmailer Attachments

$uploadedFileName = CUploadedFile::getInstance($model,'career_resume'); 
$uploadedFileName = $uploadedFile->tempName; // will be something like 'myfile.jpg'
$swiftAttachment = Swift_Attachment::fromPath($uploadedFileName);
$message->attach($swiftAttachment);

Google也如何在Swiftmailer中嵌入图片。

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...