您可以像这样将Swift_Message 添加为附件:
$attachment = new \Swift_Attachment($messageAttachment, 'some-email.txt', 'text/plain');
但是,您的电子邮件现在将作为包含所有邮件详细信息的 .txt 文件附加。我不确定这是否是预期的行为!?
完整示例:
$messageAttachment = (new \Swift_Message('Attached Email'))
->setFrom('yourmail@gmail.com')->setTo('yourmail@gmail.com')
->setBody("Attached Email Body", 'text/plain');
$attachment = new \Swift_Attachment($messageAttachment, 'some-email.txt', 'text/plain');
$message = (new \Swift_Message('Real Email'))
->setFrom('yourmail@gmail.com')->setTo('yourmail@gmail.com')
->setBody("Real Email Body", 'text/plain')
->attach($attachment);
$mailer->send($message);
所附some-email.txt 的内容如下所示:
Message-ID: <568d128d97e530d1389cb83b154d64eb@swift.generated>
Date: Tue, 05 Dec 2017 17:00:05 +0100
Subject: Attached Email
From: yourmail@gmail.com
To: yourmail@gmail.com
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
Attached Email Body