For some reason that I cannot figure out, my plugin is sending 2 emails to each user instead on one. It sends the email on hit of an action url. Below is the function in my controller. Any help is greatly appreciated.

public function actionSendEmail()

    $date = new DateTime();
    $date->modify('-7 days');

    // Format datetime for use in query
    $timezone = new \DateTimeZone(DateTime::UTC);
    $date = $date->format(DateTime::MYSQL_DATETIME, $timezone);

    $criteria = craft()->elements->getCriteria(ElementType::Entry);
    $criteria->section = 'guide';
    $criteria->order = 'postDate desc';
    $criteria->dateUpdated = '> '.$date;

    $entries = $criteria->find();

    if ($entries) {

        $user_criteria = craft()->elements->getCriteria(ElementType::User);
        $user_criteria->groupId = '9';
        $users = $user_criteria->find();

        //Send to each User
        foreach ($users as $user) {
            //Send Mail
            $email = new EmailModel();
            $email->toEmail = $user->email;
            $email->subject = 'Updated in the Last 7 Days';
            $email->htmlBody    = 'Body Goes Here';


    // Redirect after sending to each user in the loop to avoid 404

    else {
        // do nothing and redirect to avoid 404

1 Answer 1


So, this was being caused by selecting my action url from Chrome's url complete suggestions. Apparently, this submits the page twice. If the action url is typed in, pasted in or hit by my Chron job it works as expected. Firefox url suggest selection causes no problems.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.