Skip to content

Instantly share code, notes, and snippets.

@evgv
Forked from damiann/send_email
Last active June 27, 2016 10:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evgv/cf073067a3874c25c56e7f03e9d3129a to your computer and use it in GitHub Desktop.
Save evgv/cf073067a3874c25c56e7f03e9d3129a to your computer and use it in GitHub Desktop.
Magento. 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