0

i would like to add the Attachment using below Magento model.

i have tried to add

$mail->getMail()->createAttachment(
    file_get_contents($fileName), //location of file
    Zend_Mime::TYPE_OCTETSTREAM,
    Zend_Mime::DISPOSITION_ATTACHMENT,
    Zend_Mime::ENCODING_BASE64,
    'file.csv'
);

with below model.

$mail = Mage::getModel('core/email')
    ->setToName($senderName)
    ->setToEmail($customerEmail)                    
    ->setBody($processedTemplate)
    ->setSubject('Subject')
    ->setFromEmail($senderEmail)
    ->setFromName($senderName)
    ->setType('html')
    ->send();

It's Correct ? Any Help Much Appreciation! Thanks

  • @user1988065 sorry, not my question ;) – sv3n Oct 30 '18 at 20:32
  • @mahmoudismail were you ever able to resolve this issue? – user1988065 Oct 31 '18 at 12:04
0

Try this code for sending mail with attachment

$emailTemplate = Mage::getModel('core/email_template')->loadDefault('your_email_template');
$senderName = Mage::getStoreConfig('trans_email/ident_general/name');
$senderEmail = Mage::getStoreConfig('trans_email/ident_general/email');
$emailTemplateVariables = array();
$emailTemplateVariables['var1'] = $var1;
$emailTemplateVariables['var2'] = $var2;
$processedTemplate = $emailTemplate->getProcessedTemplate($emailTemplateVariables);
$mailTemplate = Mage::getModel('core/email_template')->loadDefault('your_email_template');
$mailTemplate->setSenderName($name); // use general Mage::getStoreConfig('trans_email/ident_general/name');
$mailTemplate->setSenderEmail($email); // use general Mage::getStoreConfig('trans_email/ident_general/email')
$mailTemplate->setTemplateSubject('Subject :Bulkorder notification');
$mailTemplate->setTemplateText($processedTemplate);
// add attachment
$receivermail='aa@test.com';
$receivermail='AA AA';

      $mailTemplate->getMail()->createAttachment(file_get_contents($csvfilename),
          Zend_Mime::TYPE_OCTETSTREAM,
          Zend_Mime::DISPOSITION_ATTACHMENT,
          Zend_Mime::ENCODING_BASE64,
          $attachmentname
      );
    try{
            $mailTemplate->send($receivermail, $receivermail);
    }
    catch(Exception $error)
    {
        Mage::getSingleton('core/session')->addError($error->getMessage());
        return false;
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.