Concrete5.7.5.2 - Where to put form file attachment headers?
Permalink
I build my email headers like this:
But where do I put headers for a file attachment? Where can I find out more about what really sends the message (is it still a Zend Mail?) and what methods are available?
Thank you.
$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();
But where do I put headers for a file attachment? Where can I find out more about what really sends the message (is it still a Zend Mail?) and what methods are available?
Thank you.
Got it! Got it! Got it!
Here's a working code for attaching files to your form:
Here's a working code for attaching files to your form:
$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); $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);
Viewing 15 lines of 16 lines. View entire code block.
I've just realized, even though that works, but there is an unwanted effect - it saves all the uploaded files in the file manager. This is not what I need. All I need is to send an attached file by email, it should not save it on the server anywhere. Is there any other way to attach a file, without the file importer? Thank you.
I hoped there would be a better way than uploading a file and then deleting it. Is there?
But in case someone doesn't want it on the server in the file manager, you can delete it after sending the mail:
PS. Don't forget to check the file really selected/exists/uploaded before you try to send it!
But in case someone doesn't want it on the server in the file manager, you can delete it after sending the mail:
@$mh->sendMail(); $attachment->delete();
PS. Don't forget to check the file really selected/exists/uploaded before you try to send it!
but $file must be a file object. How can I make the uploaded file a file object?
I also found this post:http://www.adrikodde.nl/blog/2012/mail-attachments-concrete5/...
But I get errors for all Zend stuff. Is Zend Mail still available in C5.7?