Email 混凝土5.7.5.2-将表格文件附件标题放在何处?

Email 混凝土5.7.5.2-将表格文件附件标题放在何处?,email,email-attachments,concrete5-5.7,Email,Email Attachments,Concrete5 5.7,我构建的电子邮件标题如下所示: $txt_message .= $this->txt_message; $html_message .= $this->html_message; $mh = Core::make('helper/mail'); $mh->to($this->email_to, $this->site_name); $mh->from($this->email, $this->name); $mh->replyto($this

我构建的电子邮件标题如下所示:

$txt_message .= $this->txt_message;
$html_message .= $this->html_message;
$mh = Core::make('helper/mail');
$mh->to($this->email_to, $this->site_name);
$mh->from($this->email, $this->name);
$mh->replyto($this->email, $this->name);
$mh->setSubject($this->subject);
$mh->setBody($txt_message);
$mh->setBodyHtml($html_message);
@$mh->sendMail();
一些帖子说可以添加附件

$mh->addAttachment($file);
但是$file必须是文件对象。如何使上载的文件成为文件对象

我还发现了以下帖子:

但是所有Zend的东西我都会出错。Zend Mail在C5.7中仍然可用吗

我在哪里放置文件附件的标题?我在哪里可以找到更多关于真正发送消息的内容(它仍然是Zend邮件吗?)以及可用的方法

多谢各位

[已解决]
感谢Nicolai,这里有一个附加文件的工作示例:

$file = $_FILES['image']['tmp_name'];
$filename = $_FILES['image']['name'];
$importer = new \Concrete\Core\File\Importer();
$file_version = $importer->import($file, $filename);
$attachment = $file_version->getFile();
$mh->addAttachment($attachment);

//Delete the file if not wanted on server
$attachment->delete();
另外,在发送文件之前,不要忘记检查文件是否真的被选中/存在/上传

if (!empty($this->image)) {
    $importer = new \Concrete\Core\File\Importer();
    $image_version = $importer->import($this->image, $file_name);
    if ($image_version instanceof \Concrete\Core\File\Version) {
        $attachment = $image_version->getFile();
        $mh->addAttachment($attachment);
    }
}
@$mh->sendMail();

要将该文件添加到文件系统中,您应该查看以下内容


在返回的对象(成功时为
FileVersion
)上,您应该能够调用
getFile()
来获取实际的具体对象
File
object

Nicolai,我尝试了$File=$\u FILES['photo']['tmp\u name']$filename=$_文件['photo']['name']$importer=new\Concrete\Core\File\importer()$结果=$importer->import($file,$filename)$mh->addAttachment($result);但它给了我一个错误:“传递给Concrete\Core\Mail\Service::addAttachment()的参数1必须是Concrete\Core\File\File的实例,Concrete\Core\File\Version的实例”这个示例也是从这里开始的:明白了!知道了!知道了!我忘记了$file\u version=$importer->import($file,$filename)$附件=$file_version->getFile();现在它工作了!!!非常感谢你,Nicolai,感谢你对我刚刚意识到的getFile()的建议,尽管这是可行的,但有一个不必要的影响——它将所有上传的文件保存在文件管理器中。这不是我需要的。所有我需要的是发送一个附件的电子邮件,它不应该保存在服务器上的任何地方。没有文件导入器,是否有其他附加文件的方法?谢谢,嗯。。我认为“简单”的方法是在以后删除该文件。否则,mailer对象(来自C5)似乎是Zend邮件对象的一个子类。所以你可以找到C5版本,看看文档是的,这就是我必须做的。但我认为应该有一个更好的方法,不需要上传然后删除。