We have created custom form module. We don't want to save the attachment, but send it via mail. I have tried below code :
<?php
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->setToName($name);
$mail->setToEmail($to);
$mail->setBody($body);
$mail->setSubject($subject);
$mail->setFromEmail($from);
$mail->setType('html');// YOu can use Html or text as Mail format
$mail->send();
Mage::getSingleton('core/session')->addSuccess('Your inquiry was submitted and will be responded to as soon as possible. Thank you for contacting us.');
$this->_redirect('*/*/');
return;
} catch (Exception $e) {
Mage::getSingleton('core/session')->addError('Unable to submit your request. Please, try again later');
$this->_redirect('*/*/');
return;
}
} else {
$this->_redirect('*/*/');
}
}
}