我像这样构建我的电子邮件标题:
$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 必须是文件对象。如何使上传的文件成为文件对象?
我还发现了这篇文章: http: //www.adrikodde.nl/blog/2012/mail-attachments-concrete5/
但是我得到所有 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();
PS。在尝试发送之前,不要忘记检查文件是否真正选择/存在/上传!
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();