9.3. 发送附件

给邮件添加附件是相当容易的;你可以使用简单便利的方法来添加附件,当然你也可以自己构造这个方法。

简单便利的方法:

<?php
$file_path = '/path/to/file.pdf';
$mime_type = 'application/pdf';

// this will automatically set the attachment name
// to the basename() of the attached file
$mail = Solar::factory('Solar_Mail_Message');
$mail->attachFile($file_name, $mime_type);
?>

或者你可以自己构建和添加MIME部分:

<?php
$file_path = '/path/to/file.pdf';
$mime_type = 'application/pdf';

$part = Solar::factory('Solar_Mail_Message_Part');
$part->setDisposition('attachment');
$part->setFilename(basename($file_name));
$part->setContent(file_get_contents($file_name));
$part->setType($mime_type);

$mail = Solar::factory('Solar_Mail_Message');
$mail->addPart($part);
?>