【问题标题】:How can I send a base64 encoded image with TYPO3如何使用 TYPO3 发送 base64 编码图像
【发布时间】:2015-09-15 20:22:08
【问题描述】:

我想通过 TYPO3 Swift Mailer 发送一个 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 编码字符串,例如: 数据:图像/png;base64,iVBORw0KGgoAAAANSUhEUgA...

那么我可以做些什么来获得一个可见的图像作为附件?我需要一个特定的标题吗?

【问题讨论】:

    标签: base64 email-attachments typo3-6.2.x


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-11
      • 1970-01-01
      • 2017-03-20
      • 2021-04-16
      相关资源
      最近更新 更多