【发布时间】:2014-08-06 03:40:56
【问题描述】:
我正在使用 Laravel 3 的 Swiftmailer 包并尝试将上传的文件附加到电子邮件中:
$message = \Message::bcc(preg_split('/,/', preg_replace('/\s+/', '', $to)))
->from(Input::get('from'))
->subject(Input::get('subject')
->body(Input::get('message'));
$attachment_path = null;
if (Input::has_file('attachment')) {
$filename = Input::file('attachment.name')
$attachment_path = path('storage') . "files/attachments/";
if (Input::upload('attachment', $attachment_path, $filename)) {
$attachment_path = $attachment_path . $filename;
$attachment = Swift_Attachment::fromPath($attachment_path);
$message->attach($attachment, $filename, Input::file('attachment.type'));
}
}
$message->send();
// clear up attachments
if ($attachment_path) {
File::delete($attachment_path);
}
我已检查文件是否已正确上传,并且可以在磁盘上打开该文件。但是,当我收到电子邮件并尝试打开附件时,文件已损坏且无法打开。它有数据,但文件大小比原始文件大。
【问题讨论】:
标签: file-upload email-attachments swiftmailer laravel-3