自定义脚本中的 Magento 邮件功能

发布于 2024-10-14 04:20:02 字数 141 浏览 3 评论 0原文

我创建了一个自定义脚本来将大量客户导入到 magento 数据库中。客户需要的是,对于每 100 个进口客户,他们需要一封有关进口情况和状态的邮件。

那么我如何使用magento 邮件功能,以便我可以创建一个模板来像magento 一样发送邮件。请帮我

I have created a custom script to import a bulk number of customers to magento database. What client needed is for each 100 customers import they needed a mail about whats going on and status of the importing.

So how can i use the magento mailing functionality so that i can create a template to send mail as like magento does. Please help me

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

沒落の蓅哖 2024-10-21 04:20:02

我认为您正在寻找以下内容:

$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" => "[email protected]" );

$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() 中提取的,尚未经过测试,但是它应该足以让您入门。将其视为伪代码:)

I think you're looking for something along the following lines:

$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" => "[email protected]" );

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

Note: This was lifted from Mage_Sales_Model_Order::sendNewOrderEmail() and hasn't been tested, but it should be more than enough to get you started. Treat it as pseudo-code :)

稚气少女 2024-10-21 04:20:02

如果您只是从导入脚本执行此操作,则 PHP mail 函数应该足够了。

If you are just doing this from an import script, the PHP mail function should be more than sufficient.

爱格式化 2024-10-21 04:20:02

还可以执行 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 = "[email protected]";
        $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>";
        }       

这正是我想要的。所以可能对某些人有用。

Also can do the mailing functionality of ZEND

Here is the code

$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 = "[email protected]";
        $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>";
        }       

This one is working exactly what i wanted. So may be useful to some one.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文