Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 保存数据时在magento中发送电子邮件_Php_Email_Magento - Fatal编程技术网

Php 保存数据时在magento中发送电子邮件

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

我创建了一个简单的表单来将数据存储在数据库中,这个表单工作得非常好。其中有一个需要自动发送电子邮件的电子邮件字段

在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');
}

现在,在保存电子邮件时,需要将其发送到字段中给出的电子邮件

您可以使用以下代码发送邮件:

 $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);