Php 保存数据时在magento中发送电子邮件
我创建了一个简单的表单来将数据存储在数据库中,这个表单工作得非常好。其中有一个需要自动发送电子邮件的电子邮件字段 在Indexcontroller.php中Php 保存数据时在magento中发送电子邮件,php,email,magento,Php,Email,Magento,我创建了一个简单的表单来将数据存储在数据库中,这个表单工作得非常好。其中有一个需要自动发送电子邮件的电子邮件字段 在Indexcontroller.php中 public function createPersonAction() { $data = $this->getRequest()->getPost(); $session = Mage::getSingleton('core/session'); $person = Mage::getModel('lesson14/less
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');
}
现在,在保存电子邮件时,需要将其发送到字段中给出的电子邮件 您可以使用以下代码发送邮件:
$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);