/** Email a search result */ public function emailAction() { $user = $this->getAccount(); $this->view->headTitle('Email this search to another person'); $searches = new Searches(); $lastsearch = $searches->fetchRow($searches->select()->where('userid = ?', $this->getIdentityForForms())->order('id DESC')); if (count($lastsearch)) { $querystring = unserialize($lastsearch->searchString); $params = array(); $query = ''; foreach ($querystring as $key => $value) { $query .= $key . '/' . $value . '/'; $params[$key] = $value; } $this->view->params = $params; $form = new EmailSearchForm(); $this->view->form = $form; if ($this->_request->isPost()) { $data = $this->_getAllParams(); if ($form->isValid($data)) { $sender = $user->fullname; $senderemail = $user->email; $recipient = $form->getValue('fullname'); $recipientemail = $form->getValue('email'); $message = $form->getValue('messageToUser'); $strippedmessage = strip_tags($message); $url = 'http://' . $_SERVER['SERVER_NAME'] . '/database/search/results/' . $query; $mail = new Zend_Mail(); $mail->addHeader('X-MailGenerator', 'The Portable Antiquities Scheme\'s awesome database'); $mail->setBodyHtml('<p>Dear ' . $recipient . '</p>' . $message . '<p>Located at this url: ' . $url . '</p><p>From ' . $sender . '</p>'); $mail->setFrom('*****@*****.**', 'The Portable Antiquities Scheme'); $mail->setBodyText('Dear ' . $recipient . ',' . $message . ' ' . $url . 'From,' . $sender); $mail->addTo($recipientemail, $recipient); $mail->addCC($senderemail, $sender); $mail->setSubject('I thought you might be interested in this search on the PAS Database.'); $mail->send(); $this->_flashMessenger->addMessage('Your email has been sent to ' . $recipient . '. Thank you for sending them some of our records.'); $this->_redirect('/database/search/results/' . $query); } else { $form->populate($data); } } } else { $this->_flashMessenger->addMessage('You haven\'t ever searched, so you have nothing to email!'); $this->_redirect('/database/search/'); } }