简体   繁体   English

如何连续执行发送邮件的脚本?

[英]How do I continuously execute my script for sending mails?

I want my part of my Magento code to continuously execute. 我希望我的Magento代码能够持续执行。 For example: If I want to send mail for those customers who have not ordered any product from last 3 month. 例如:如果我想为过去3个月未订购任何产品的客户发送邮件。 So in this case i have to find mail triggering timings for them. 所以在这种情况下,我必须为他们找到邮件触发时间。

Consider A customer have not ordered and its 3 months completed on particular day on morning And B customer have not ordered and its 3 months completed on same day(as A customer) in evening 考虑客户尚未订购,并且在上午的特定日期完成了3个月而B客户尚未订购,并且在晚上(作为A客户)在晚上完成了3个月

How can I do in such condition? 我怎么能在这种情况下做?

I expect the output For A customer's mail send on morning And For B customer's mail send on evening 我希望早上发送客户邮件的输出,晚上发送客户的邮件

You gonna need Cron Job to send emails periodically 你需要Cron Job定期发送电子邮件

You have to write Crontab in your config.xml 您必须在config.xml中编写Crontab

     <crontab>
        <jobs>
          <custom_cron_task>
            <schedule>
              <cron_expr>0 0 0 ? 1/3 * *</cron_expr>
            </schedule>
            <run>
              <model>cron/cron::crontask</model>
            </run>
          </custom_cron_task>
        </jobs>
      </crontab>
  <global>
    <models>
      <cron>
       <class>Your_Model</class>
      </cron>
    </models>
  </global>

element under the element defines the interval on which the job will run regularly. 元素下的元素定义作业定期运行的时间间隔。 In the above case, the cron job will run in every 3 months. 在上述情况下,cron作业将每3个月运行一次。

and create your cron.php in your model 并在模型中创建cron.php

<?php

class Namespace_Mymodule_Model_Cron
{
 public function customtask()
 {
   // send email
   $mail = Mage::getModel('core/email')
    ->setToEmail('user@email.com')
    ->setBody('Body of the Automated Cron Email Goes Here')
    ->setSubject('Subject: Cron Task (every 3 months) '.date("Y-m-d H:i:s"))
    ->setFromEmail('admin@example.com')
    ->setFromName('Your Store Name')
    ->setType('html');
   $mail->send();
 }
}

Hope this will work for you. 希望这对你有用。 Thanks 谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM