-1

I created a simple form to store the data in the database which is working perfectly. In that there is a email field for which an email needs to be sent automatically.

In Indexcontroller.php

public function createPersonAction()
{
$data = $this->getRequest()->getPost();
$session = Mage::getSingleton('core/session');
$person = Mage::getModel('lesson14/lesson14');
$person->setData('name', $data['name']);
$person->setData('birthday', $data['birthday']);
$person->setData('gender', $data['gender']);
$person->setData('address', $data['address']);
$person->setData('email',$data['email']);

// $person->setData($data);
try{
$person->save();
$session->addSuccess('Person Added sucessfully');
}catch(Exception $e){
$session->addError('Add Error');
}

now while saving an email needs to be sent to the email that is given in the field.

John Conde
  • 217,595
  • 99
  • 455
  • 496
Mujtaba M
  • 5
  • 2

1 Answers1

0

You can following code to send mail:

 $storeid = Mage::app()->getStore()->getStoreId();
$templateId = "Template Name"; //create new template from system -> transactional email 
$emailTemplate = Mage::getModel('core/email_template')->loadByCode($templateId);
$vars = array('user_name' => $userName, 'product_name' => $productName);
  $emailTemplate->setSenderEmail(Mage::getStoreConfig('trans_email/ident_general/email', $storeId));

  $emailTemplate->setSenderName(Mage::getStoreConfig('trans_email/ident_general/name', $storeId));

 //And finally, we send out the email:

 $emailTemplate->send($receiveEmail,$receiveName, $vars);