public function executeResult() { $this->setLayout(false); if ($code = $this->getRequestParameter("codeid")) { $c = new Criteria(); $c->add(SubscriberPeer::CODE, $code); $user = SubscriberPeer::doSelectOne($c); if ($user) { $user->setPublicationStatus(UtilsHelper::STATUS_ACTIVE); //$user->setCode(null); $user->save(); $this->msg = "Subscribtion confirmed"; } else { $this->err = "A problem occured"; } return "Confirm"; } $email = trim($this->getRequestParameter('newsletter_email')); if (!empty($email)) { $new = false; $c = new Criteria(); $c->add(SubscriberPeer::EMAIL, $email); $c->add(SubscriberPeer::PUBLICATION_STATUS, UtilsHelper::STATUS_WAITING); $subscriber = SubscriberPeer::doSelectOne($c); if (!$subscriber) { $subscriber = new Subscriber(); $subscriber->setLabel($email); $subscriber->setEmail($email); $code = md5(time()); $subscriber->setCode($code); $new = true; } else { $code = $subscriber->getCode(); } $from_name = UtilsHelper::SYSTEM_SENDER; $from_email = UtilsHelper::NO_REPLY_MAIL; $mail = new sfMail(); $mail->initialize(); $mail->setMailer('sendmail'); $mail->setCharset('utf-8'); $mail->setSender($from_email, $from_name); $mail->setFrom($from_email, $from_name); $mail->addReplyTo($from_email); $mail->addAddress($email); $mail->addBcc(UtilsHelper::COPY_MAIL); $mail->setContentType('text/html'); $mail->setSubject('Newsletter subscribtion'); $resultPage = Document::getDocumentByExclusiveTag('website_page_newsletter_result'); if ($resultPage) { $resultPageHref = $resultPage->getHref(); } $request = $this->getRequest(); $request->setParameter('activationUrl', $resultPageHref . "?codeid=" . $code); $body = $this->getPresentationFor("newsletter", "confirmMail"); $mail->setBody($body); try { $mail->send(); $defMailinglist = Document::getDocumentByExclusiveTag('newsletter_mailinglist_default'); if ($defMailinglist && $new) { $subscriber->save(null, $defMailinglist); $subscriber->setPublicationStatus(UtilsHelper::STATUS_WAITING, true); } $this->msg = "Subscribtion successfull, check your email"; } catch (Exception $e) { $this->getRequest()->setError('newsletter_email', "A problem occured"); } } else { $this->getRequest()->setError('newsletter_email', "Please enter your email"); $this->form = true; } }