We have created custom form module. We don't want to save the attachment, but send it via mail. I have tried below code(controller file) :

class Vendor_Module_IndexController extends Mage_Core_Controller_Front_Action { 
public function indexAction()
    $this->loadLayout(); $this->renderLayout(); 

public function postAction()
    $post = $this->getRequest()->getPost();

    if ($post){
        try {
            $name = $post["name"];
            $email = $post["email"];
            $address_line_1 = $post["address_line_1"]; 
            $phone_number = $post["phone_number"]; 
            $adhar_number = $post["adhar_number"]; 
            $pan_number = $post["pan_number"]; 
            /* $image=$_FILES["uploaded_file"]["name"]; */              
                    /* $target_path = "image/";  
                    $folder = $target_path.basename( $_FILES['fileToUpload']['name']);   
                    move_uploaded_file($_files["uploaded_file"]["tmp_name"],$folder);  */   

            $lone_type = $post["lone_type"]; 

            $to = "nehaseekhwal31@gmail.com";
            $subject = "Inquiry Form For Lone";
            $body .= "<p>The following customer have requested for lone.</p>";
            $body .= "<p>Name : " . $name . "<p>";
            $body .= "<p>Email  : " . $email . "<p>";
            $body .= "<p>Full Address : " . $address_line_1 . "<p>";
            $body .= "<p>Phone Card Number : " . $phone_number . "<p>";
            $body .= "<p>Adhar Card Number : " . $adhar_number . "<p>";
            $body .= "<p>Pan Card Number : " . $pan_number . "<p>";         
            $body .= "<p>Lone Type : " . $lone_type . "<p>";
            $body .= "<br/><p>Kind regards,</p><p>$name</p>";

            $from = $email;

            $mail = Mage::getModel('core/email');
            $mail->setType('html');// YOu can use Html or text as Mail format

            // Attachment Code

             $file       = $_FILES["uploaded_file"] ["name"];
            $attachment = file_get_contents($file);

            // Attachment Code


            Mage::getSingleton('core/session')->addSuccess('Your inquiry was submitted and will be responded to as soon as possible. Thank you for contacting us.');
        } catch (Exception $e) {
            Mage::getSingleton('core/session')->addError('Unable to submit your request. Please, try again later');
    } else {

This is my phtml code

<form action="<?php echo $this->getUrl('brochure/index/post'); ?>" id="brochureform" class="contact-page-bg" method="post" enctype="multipart/form-data">

<h3 class="margin-bottom15">Enquiry form</h3>
<ul class="form-list">
    <li class="form-group"><label class="required">Name</label><br>
    <input class="input-text required-entry" id="name" name="name" type="text"></li>

    <li class="form-group"><label class="required">Email</label><br>
    <input class="input-text required-entry" id="email" name="email" type="text"></li>

    <li class="form-group"><label class="required">Full Address</label><br>
    <input class="input-text required-entry" id="address_line_1" name="address_line_1" type="text"></li>

    <li class="form-group"><label class="required">Phone Number</label><br>
    <input class="input-text required-entry" id="phone_number" name="phone_number" type="text"></li>

    <li class="form-group"><label class="required">Adhar Card Number</label><br>
    <input class="input-text required-entry" id="adhar_number" name="adhar_number" type="text"></li>

    <li class="form-group"><label class="required">Pan Card Number</label><br>
    <input class="input-text required-entry" id="pan_number" name="pan_number" type="text"></li>

    <li class="col-md-6 col-sm-6 col-xs-12 form-group"><label>Attached File</label><br>
    <input type="file" name="uploaded_file">

    <li class="form-group"><label class="required">Lone type</label><br>
    <select class="input-text required-entry" id="lone_type" name="lone_type" class="lone_type">
          <option>--Select Lone--</option>
          <option value="Personal Loan">Personal Loan</option>
          <option value="Business Loan">Business Loan</option>

<div class="buttons-set">
<button class="button btn btn-primary" type="submit"><span><span>Submit Your Request</span></span></button>

Your Answer

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

Browse other questions tagged or ask your own question.