Script run 2 times, needed only 1 time

97 views Asked by At

I use this script to send email after comment, it's k2 component from joomla, but i get every time 2 emails, how can i count runs and start this script only 1 time?

my code looks so:

        $mailer =& JFactory::getMailer();
    $config =& JFactory::getConfig();
    $sender = array(
    $config->getValue( 'config.mailfrom' ),
    $config->getValue( 'config.fromname' ) );
    $mailer->setSender($sender);
    $recipient = explode(",", " [email protected]");
    $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();            
1

There are 1 answers

0
Fez Vrasta On BEST ANSWER
$first = true;
if($first) {

   ...code...

   $first = false;
 }

But I think would be better understand where is the problem with the component developer.