send mail with attachment

Submitted by remo - 2 years ago

Sometimes you want to attach a file to an e-mail. In concrete5 this is surprisingly difficult, but if you have a the proper recipe you shouldn't have a long time to get it working, check below!


$mh = Loader::helper('mail');

// create a file in mails/mail_template.php the usual way
// we need to get access to the underlying zend mail object
$zendMailerObject = $mh->getMailerObject();
$zendMailer = $zendMailerObject['mail'];
$fileContent = file_get_contents($fileName);
$attachment = new Zend_Mime_Part($fileContent);
$attachment->filename  = basename($fileName);
$attachment->type = 'application/pdf';
$attachment->encoding = Zend_Mime::ENCODING_BASE64;
$attachment->disposition = Zend_Mime::DISPOSITION_INLINE;
Stats Categories Tags
comments powered by Disqus