我创建了一个简单的表单来将数据存储在数据库中,该表单工作正常。在那里有一个电子邮件字段,需要自动发送电子邮件。
在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');
}
现在,保存电子邮件需要发送到该字段中提供的电子邮件。
答案 0 :(得分:0)
您可以按照以下代码发送邮件:
$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);