Hi I create cusrom form(frontend). And I want to sent Transactional Email with file .

Below is IndexController and file template send_email.phtml



class Send_Email_IndexController extends Mage_Core_Controller_Front_Action
    public function indexAction()
        //Get current layout state

        $block = $this->getLayout()->createBlock(
                'template' => 'send_email/simple_contact.phtml'

        //$this->getLayout()->getBlock('right')->insert($block, 'catalog.compare.sidebar', true);



    public function sendemailAction()
        if ($error) {
            throw new Exception();

        //Fetch submited params
        $params = $this->getRequest()->getParams();

        $mail = new Zend_Mail();
        $mail->setFrom($params['email'], $params['name']);
        $mail->addTo('[email protected]', 'Some Recipient');
        $mail->setSubject('Test Email Module for Magento');
        try {
            Mage::getSingleton('core/session')->addSuccess('send email.');
        catch(Exception $ex) {
            Mage::getSingleton('core/session')->addError('Unable to send email.');


        //Redirect back to index action of (this) inchoo-simplecontact controller

template send_email.phtml:

<div class="box simple_contact">

    <form id="simple_contact_form" name="simple_contact_form" action="<?php echo $this->getUrl('email/') ?>index/sendemail" method="post" enctype="multipart/form-data">

        <fieldset class="group-select">
            <h4 class="legend">Simple Contact Form</h4>
                    <div class="input-box">
                        <label for="name">Gimme your name <span class="required">*</span></label><br />

                        <input name="name" id="name" title="Name" value="" class="input-text required-entry" type="text" />

                    <div class="input-box">
                        <label for="email">And your email <span class="required">*</span></label><br />
                        <input name="email" id="email" title="Email" value="" class="input-text required-entry validate-email" type="text" />

                    <div class="clear"></div>
                    <label for="attachment"><?php echo Mage::helper('contacts')->__('Attachment') ?></label>
                    <div class="input-box">
                        <input name="MAX_FILE_SIZE" type="hidden" value="2000000" />
                        <input name="customerimg" id="attachment" class="input-text" type="file" />
        <div class="button-set">
           <button type="submit" title="Submit" class="button"><span><span>Submit</span></span></button>

<script type="text/javascript">
    var contactForm = new VarienForm('simple_contact_form', true);

1 Answer 1


You should first get the file, save it, get the contents (or convert it to base 64 if you don't want to save it) and then add it as an attachment. You are using zend_mail so this documentation should help you do it:


Please refer to this documentation:


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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