我创建了一个自定义脚本来将大量客户导入 magento 数据库。客户需要的是每 100 个客户进口,他们需要一封关于进口情况和状态的邮件。
那么我如何使用 magento 邮件功能,以便我可以创建一个模板来像 magento 一样发送邮件。请帮我
我创建了一个自定义脚本来将大量客户导入 magento 数据库。客户需要的是每 100 个客户进口,他们需要一封关于进口情况和状态的邮件。
那么我如何使用 magento 邮件功能,以便我可以创建一个模板来像 magento 一样发送邮件。请帮我
我认为您正在寻找以下方面的内容:
$store_id = $this->getStoreId();
$template = "import_script_email_template_name";
$from = Mage::getStoreConfig(self::XML_PATH_EMAIL_IDENTITY, $store_id);
$to = array( "name" => "Nick", "email" => "the@email.address" );
$template_variables = array(
"var1" => "somevalue",
"var2" => "someothervalue"
);
$mail = Mage::getModel("core/email_template");
$mail->setDesignConfig( array( "area" => "frontend", "store" => $store_id ))
->sendTransactional(
$template_name,
$from,
$to["email"],
$to["name"],
$template_variables
);
注意:这是从Mage_Sales_Model_Order::sendNewOrderEmail()
没有经过测试的,但它应该足以让你开始。将其视为伪代码:)
If you are just doing this from an import script, the PHP mail function should be more than sufficient.
也可以做ZEND的邮件功能
这是代码
$mail_body = "<h3> These are ordered by you in the event - '".$customer_event."' </h3> <br/>". $email_body;
$to_email = $email;
$to_name = $customer_name;
$subject = 'Orders';
$Body = $body;
$sender_email = "info@mail.com";
$sender_name = "mail";
$html = new Zend_View();
$html->setScriptPath('app/locale/en_US/template/email/');
$html->assign('customer_name', $customer_name);
$html->assign('email', $to_email);
$html->assign('password', $password);
$html->assign('site_url', Mage::getUrl(""));
$html->assign('site_skin_url', Mage::getDesign()->getSkinUrl("images/"));
$html->assign('site_order_url', Mage::getUrl("").'Event.php?id='.$id.'&cart_id='.$cart_id);
$html->assign('site_name', 'Winecellarage');
$html->assign('site_data', $mail_body);
$Body_text= $html->render($template);
$mail = new Zend_Mail('utf-8');
$mail->setBodyHtml($Body_text);
$mail->setFrom($sender_email, $sender_name);
$mail->addTo($to_email, $to_name);
//$mail->addCc($cc, $ccname);
//$mail->addBCc($bcc, $bccname);
$mail->setSubject($subject);
try {
if($mail->send())
{
$msg .= "<p>Mail sent successfully to '$to_email' </p>";
}
}
catch(Exception $ex) {
$err .= '<p>'.$error_msg = $ex->getMessage()."</p>";
}
这正是我想要的。所以可能对某些人有用。