【问题标题】:Script run 2 times, needed only 1 time脚本运行 2 次,只需要 1 次
【发布时间】:2013-09-05 16:45:24
【问题描述】:

我使用此脚本在评论后发送电子邮件,它是来自 joomla 的 k2 组件,但我每次收到 2 封电子邮件,我如何计算运行次数并仅启动此脚本 1 次?

我的代码是这样的:

        $mailer =& JFactory::getMailer();
    $config =& JFactory::getConfig();
    $sender = array(
    $config->getValue( 'config.mailfrom' ),
    $config->getValue( 'config.fromname' ) );
    $mailer->setSender($sender);
    $recipient = explode(",", " marco3pollini@gmail.com");
    $mailer->addRecipient($recipient);
    $mailer->setSubject(JText::_('New comment is arrived'));
    if (!trim($commentURL)=="") {
    $commentURL = "Site: ". $commentURL. "\n";
    }
    $body = "Name: ". $userName. "\n". "E-mail: ". $commentEmail. "\n". $commentURL. "Comment: ". $commentText;
    $mailer->setBody($body);
    $mailer->isHTML(true);
    $mailer->Send();            

【问题讨论】:

  • 你应该从源头上解决问题,弄清楚为什么它被调用了两次。

标签: php joomla joomla-k2


【解决方案1】:
$first = true;
if($first) {

   ...code...

   $first = false;
 }

但我认为更好地了解组件开发人员的问题在哪里。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-10-16
    • 2021-12-30
    • 2020-07-19
    • 2012-01-08
    • 2015-04-09
    相关资源
    最近更新 更多