protected function _getSubscriberForm() { $form = new Application_Form_SubscriberAdd(); if (!$this->getRequest()->isPost()) { $this->view->subscriberform = $form; return; } if ($_POST['submit'] == 'Subscribe') { if (!$form->isValid($_POST)) { $this->view->errors = $form->getMessages(); $this->view->subscriberform = $form; return; } $values = $form->getValues(); $data = array('email' => $values['subscribeemail']); $subscriber_mapper = new Application_Model_SubscriberMapper(); if (!($subscriber = $subscriber_mapper->findByEmail($values['subscribeemail']))) { $subscriber = new Application_Model_Subscriber($data); } $id = $subscriber_mapper->save($subscriber); // Send email notifications $hashid = md5($id . 'bugger'); $unsubscribe = "<a href=\"{$this->message_details['url']}/blog/unsubscribe/id/{$id}/sess/{$hashid}\">unsubscribe</a>"; $mail = new Zend_Mail(); $mail->setFrom($this->message_details['email'], 'Blogger'); $mail->addTo($values['subscribeemail']); $mail->setSubject($this->message_details['blog']); $mail->setBodyText("Thanks for subscribing to my blog. If you change you mind you can {$unsubscribe}"); $mail->setBodyHtml("<p>Thanks for subscribing to my blog. If you change you mind you can {$unsubscribe}</p>"); $mail->send(); $mail = new Zend_Mail(); $mail->setFrom('*****@*****.**', 'Frog Princess'); $mail->addTo($values['subscribeemail']); $mail->setSubject('New subscription'); $mail->setBodyText($values['subscribeemail']); $mail->setBodyHtml($values['subscribeemail']); $mail->send(); $this->view->message = "<i>New post notifications will be sent to: {$values['subscribeemail']}</i>"; } // Add the form to the view $form->reset(); $this->view->subscriberform = $form; }
protected function _emailSubscribers($entry) { $subscriber_mapper = new Application_Model_SubscriberMapper(); $subscribers = $subscriber_mapper->findAll(); $message_details = Zend_Registry::get('config.message'); foreach ($subscribers as $subscriber) { // Send email notification $hashid = md5($id . 'bugger'); $unsubscribe = "<a href=\"{$message_details['url']}/blog/unsubscribe/id/{$subscriber->id}/sess/{$hashid}\">unsubscribe</a>"; $url = "<a href=\"{$message_details['url']}{$this->view->EntryUrl($entry)}\">Read it</a>"; $mail = new Zend_Mail(); $mail->setFrom($message_details['email'], $message_details['name']); $mail->addTo($subscriber->email, ''); $mail->setSubject('[New post] ' . $message_details['blog']); $mail->setBodyText("{$entry->title} {$url} \n {$unsubscribe}"); $mail->setBodyHtml("<p>{$entry->title} {$url}</p><p>{$unsubscribe}</p>"); $mail->send(); } }