如何发送带有 TYPO3 的 base64 编码图像

How can I send a base64 encoded image with TYPO3

我想通过 TYPO3 Swift 邮件程序发送 base64 编码的图像,但它没有按预期工作:

$mail = GeneralUtility::makeInstance('TYPO3\CMS\Core\Mail\MailMessage');
$mail->setFrom(array($fromEmail => $fromName));
$mail->setTo(array($toEmail => $toName));
$mail->setSubject($subject);
$mail->setBody($body, 'text/html');

if ($data->attachmentExists()) {
    $attachment = \Swift_Attachment::fromPath($data->getBase64());
    $mail->attach($attachment);
}

$mail->send();

邮件将被正确发送,但附件不是预期的图像且无法查看。

base64 属性:

$data->getBase64()

表示图像的 base64 编码字符串,例如: 数据:image/png;base64,iVBORw0KGgoAAAANSUhEUgA...

那么,我该怎么做才能将可见图像作为附件?我需要特定的 header 吗?

好的,如果设置了附件的内容类型就可以了:)

$attachment = \Swift_Attachment::fromPath($data->getBase64())->setContentType('image/png');