public function sendMail($mailAddresses, $subject, $newsletterHtml) { $mail = new sfMail(); $mail->initialize(); $mail->setMailer('sendmail'); $mail->setCharset('utf-8'); $mail->setSender(UtilsHelper::NEWSLETTER_FROM_MAIL, UtilsHelper::SYSTEM_SENDER); $mail->setFrom(UtilsHelper::NEWSLETTER_FROM_MAIL, UtilsHelper::SYSTEM_SENDER); $mail->addAddress(UtilsHelper::NEWSLETTER_TO_MAIL); foreach ($mailAddresses as $mailAdd) { $mail->addBcc($mailAdd); } $mail->setContentType('text/html'); $mail->setSubject($subject); $mail->setBody($newsletterHtml); $mail->send(); }
function run_newsletter($task, $args) { ini_set("memory_limit", "2048M"); define('SF_ROOT_DIR', sfConfig::get('sf_root_dir')); define('SF_APP', 'frontend'); define('SF_ENVIRONMENT', 'prod'); define('SF_DEBUG', false); require_once SF_ROOT_DIR . DIRECTORY_SEPARATOR . 'apps' . DIRECTORY_SEPARATOR . SF_APP . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php'; /*$databaseManager = new sfDatabaseManager(); $databaseManager->initialize();*/ try { $controler = sfContext::getInstance()->getController(); $newsletterHtml = $controler->getPresentationFor("news", "composeNewsletter"); $newsletter = new Newsletter(); $today = UtilsHelper::DateBG(date('Y-m-d H:i:s', time()), 'd F, Y г.'); $newsletter->setLabel($today); $newsletter->setContent($newsletterHtml); $newsletter->save(); $mailinglist = Document::getDocumentByExclusiveTag("newsletter_mailinglist_default"); if ($mailinglist) { $subscribers = Document::getChildrenOf($mailinglist->getId(), "Subscriber"); } $subject = "Sgrada.com - ежедневен бюлетин"; $i = $ind = 0; $mailAddresses = array(); $cnt = count($subscribers); foreach ($subscribers as $subscriber) { $ind++; if ($subscriber->getPublicationStatus() == "ACTIVE") { $mailAddresses[] = $subscriber->getEmail(); echo " ====> " . $subscriber->getEmail() . "\n"; $i++; } if ($i == 100 || $ind == $cnt) { if (!empty($mailAddresses)) { //sendMail($mailAddresses, $subject, $newsletterHtml); $mail = new sfMail(); $mail->initialize(); $mail->setMailer('sendmail'); $mail->setCharset('utf-8'); $mail->setSender(UtilsHelper::NO_REPLY_MAIL, UtilsHelper::SYSTEM_SENDER); $mail->setFrom(UtilsHelper::NO_REPLY_MAIL, UtilsHelper::SYSTEM_SENDER); $mail->addAddress(UtilsHelper::NO_REPLY_MAIL); foreach ($mailAddresses as $mailAdd) { $mail->addBcc($mailAdd); } $mail->setContentType('text/html'); $mail->setSubject($subject); $mail->setBody($newsletterHtml); $mail->send(); } $mailAddresses = array(); $i = 0; } } } catch (Exception $e) { $newsletter->setLabel("ERROR! " . $today); $newsletter->save(); FileHelper::Log("TASK run_newsletter: " . $e->getMessage(), UtilsHelper::MSG_ERROR); } }
public static function sendEmail($to, $body, $subject = "", $from = self::NO_REPLY_MAIL, $fromName = self::NO_REPLY_NAME, $replyTo = self::NO_REPLY_MAIL, $bcc = array(), $attachment = '') { $template_header = ''; $template_footer = ''; try { $mail = new sfMail(); $mail->initialize(); $mail->setMailer('sendmail'); $mail->setCharset('utf-8'); $mail->setContentType('text/html'); $mail->setSender($from, $fromName); $mail->setFrom($from, $fromName); $mail->addReplyTo($replyTo); $mail->addAddress($to); if (is_array($attachment)) { foreach ($attachment as $key => $row) { $mail->addAttachment($row); } } else { if ($attachment != '') { $mail->addAttachment($attachment); } } foreach ($bcc as $bcc_address) { $mail->addBcc($bcc_address); } $mail->setSubject($subject); $mail->setBody($template_header . $body . $template_footer); $mail->send(); return true; } catch (Exception $e) { return false; } }
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; } }
public function executeSendAlerts() { $user_id = $this->getRequestParameter('user_id'); $last_alert = $this->getRequestParameter('last_alert'); $this->user = OppUserPeer::retrieveByPK($user_id); $this->sf_site_url = sfConfig::get('sf_site_url', 'openparlamento'); $this->user_token = $this->user->getToken(); $this->user_alerts = oppAlertingTools::getUserAlerts($this->user, sfConfig::get('app_alert_max_results', 50), $last_alert); $this->n_alerts = OppAlertUserPeer::countUserAlerts($this->user); $this->n_total_notifications = oppAlertingTools::countTotalAlertsNotifications($this->user_alerts); // do not send email if no news if ($this->n_alerts == 0) { return sfView::NONE; } // mail class initialization $mail = new sfMail(); $mail->setCharset('utf-8'); $mail->setContentType('text/html'); // definition of the required parameters if ($this->user->isAdhoc()) { $mail->setSender(sfConfig::get('app_newsletter_pd_sender_address', '*****@*****.**'), sfConfig::get('app_newsletter_pd_from_tag', 'political desk')); $mail->setFrom(sfConfig::get('app_newsletter_pd_from_address', '*****@*****.**'), sfConfig::get('app_newsletter_pd_from_tag', 'political desk')); } else { $mail->setSender(sfConfig::get('app_newsletter_sender_address', '*****@*****.**'), sfConfig::get('app_newsletter_from_tag', 'openparlamento')); $mail->setFrom(sfConfig::get('app_newsletter_from_address', '*****@*****.**'), sfConfig::get('app_newsletter_from_tag', 'openparlamento')); } $mail->addAddress($this->user->getEmail()); // invia tutte le mail in BCC a un indirizzo di servizio if ($this->user->isAdhoc()) { $mail->addBcc('*****@*****.**'); } // alert utente espansi per il subject della mail $user_alerts_expanded = join(", ", array_map('extractTerm', array_slice($this->user_alerts, 0, 3))) . ($this->n_alerts > 3 ? ',...' : ''); $subj = sprintf("%d %s per %s che stai monitorando (%s) ", $this->n_total_notifications, $this->n_total_notifications == 1 ? 'avviso' : 'avvisi', $this->n_alerts == 1 ? 'il termine' : 'i ' . $this->n_alerts . ' termini', $user_alerts_expanded); $mail->setSubject($subj); $this->mail = $mail; }
public function executeNotifyModeratorsOnCommentWithLink() { $this->comment_object = $this->getRequest()->getAttribute('comment'); $env = sfConfig::get('sf_environment', 'prod'); $backend_controller = $env == 'prod' ? 'be.php' : "be_{$env}.php"; $this->comments_backend_url = 'http://' . sfConfig::get('sf_site_url') . "/{$backend_controller}/deppCommentingAdmin"; // do not send email if no news if (!$this->comment_object instanceof sfComment) { return sfView::NONE; } // mail class initialization $mail = new sfMail(); $mail->setCharset('utf-8'); $mail->setContentType('text/html'); // definition of the required parameters $mail->setSender(sfConfig::get('app_notifications_sender_address', '*****@*****.**'), sfConfig::get('app_notifications_from_tag', 'openparlamento')); $mail->setFrom(sfConfig::get('app_notifications_from_address', '*****@*****.**'), sfConfig::get('app_notifications_from_tag', 'openparlamento')); $moderators = array('*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**'); foreach ($moderators as $moderator) { $mail->addAddress($moderator); } // invia tutte le mail in BCC a un indirizzo di servizio $mail->addBcc('*****@*****.**'); $mail->setSubject("[openparlamento] nuovo commento contenente link"); $this->mail = $mail; }