RE: How to add an attachment in email in magento?

    I want to add a custom email script to add an attachment in  controller file

    suresh Junior Developer Asked on November 24, 2017 in MAGENTO.
    Add Comment
    1 Answers

      $ToName=”Sender Name”;
      /* Sender Email */

      $mail = new Zend_Mail();

      $mail->setFrom(‘’, ‘Your business name goes here’);
      $mail->addTo($ToEmail, $ToName);

      $sub=”Email subject goes here”;
      $dir = Mage::getBaseUrl();

      if (isset($_FILES[‘filename’][‘name’]) && $_FILES[‘filename’][‘name’] != ”) {

      $f_name=time() .”_”.$_FILES[‘filename’][‘name’];

      $uploadfile22 = $uploaddir22 . $f_name;

      if(move_uploaded_file($_FILES[‘filename’][‘tmp_name’], $uploadfile22)) {
      $filename = $f_name;
      chmod($uploadfile22, 0777);


      $ext1 = pathinfo($filename, PATHINFO_EXTENSION);
      $file = $mail->createAttachment(file_get_contents($uploadfile22));
      $file ->type = $exttype1;
      $file ->disposition = Zend_Mime::DISPOSITION_INLINE;
      $file ->encoding = Zend_Mime::ENCODING_BASE64;
      $file ->filename = $filename;


      $html = “<h1>Body of your email data goes here</h1>”;

      if (! $mail->send()) {
      throw new Exception ();
      echo “Email sent successfully”;
      catch(Exception $ex){
      echo $ex->getMessage();


      Team Leader Answered on December 4, 2017.
      Add Comment

      Your Answer

      By posting your answer, you agree to the privacy policy and terms of service.