Skip to content

Instantly share code, notes, and snippets.

@damiann
Last active October 12, 2020 16:48
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save damiann/6287556 to your computer and use it in GitHub Desktop.
Save damiann/6287556 to your computer and use it in GitHub Desktop.
Send Magento template email with attachment.
<?
// using model magento\app\code\core\Mage\Core\Model\Email\Template.php
public function send_error_email($error = NULL) {
$mailTemplate = Mage::getModel('core/email_template');
$mailTemplate->setSenderName('Insert Sender Name'); // use general Mage::getStoreConfig('trans_email/ident_general/name');
$mailTemplate->setSenderEmail('insert@sender.email'); // use general Mage::getStoreConfig('trans_email/ident_general/email')
$mailTemplate->setTemplateSubject('Insert Subject Title');
$mailTemplate->setTemplateText('Insert Body Text');
// add attachment
$mailTemplate->getMail()->createAttachment(
file_get_contents(Mage::getBaseDir('base') . '/var/log/file.log'),
Zend_Mime::TYPE_OCTETSTREAM,
Zend_Mime::DISPOSITION_ATTACHMENT,
Zend_Mime::ENCODING_BASE64,
'file.log'
);
$mailTemplate->send($to_email_arr, $to_name_arr);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment