view->form = $form; // View verarbeiten $this->render('kontakt'); } public function sendAction() { // Prüfen ob POST Request if (!$this->getRequest()->isPost()) { // Zum Formular weiter leiten return $this->_forward('index'); } // Form Objekt erstellen $form = new Application_Form_Contact(); $this->view->dataSubmitted = true; // Prüfen ob Formulardaten ungültig if (!$form->isValid($this->getRequest()->getPost())) { return $this->indexAction($form); } // Variablen an View übergeben $values = $form->getValues(); $this->view->form = $values; // E-Mail Absender $from = $values['email']; // View verarbeiten E-Mail-Template $bodyText = $this->view->render($this->getViewScript('kontakt-mail')); // Mail erstellen $mail = array( 'body' => utf8_decode($bodyText), 'from' => $from, 'subject' => 'Kontaktanfrage ALLE ZIELE' ); // Mail versenden $this->sendMail($mail); // View verarbeiten $this->render('kontakt-success'); } public function recommendAction($form = null) { if (null === $form || !($form instanceof Application_Form_Recommend)) { // Neues Formular Objekt erstellen wenn nicht mit übergeben $form = new Application_Form_Recommend(); } // Formular Objekt an View übergeben $this->view->form = $form; // jQuery einbinden $this->view->headScript()->appendFile($this->view->baseUrl('js/jquery-1.7.min.js')); // View verarbeiten $this->render('empfehlen'); } public function recommendsendAction() { // Prüfen ob POST Request if (!$this->getRequest()->isPost()) { // Zum Formular weiter leiten return $this->_forward('recommend'); } // Formular Objekt erstellen $form = new Application_Form_Recommend(); // Variable an View übergeben $this->view->dataSubmitted = true; // Prüfen ob Formulardaten ungültig if (!$form->isValid($this->getRequest()->getPost())) { return $this->recommendAction($form); } // Variablen an View übergeben $values = $form->getValues(); $this->view->form = $values; // E-Mail Empfänger $to = $values['email']; // View verarbeiten E-Mail-Template $bodyText = $this->view->render($this->getViewScript('empfehlen-mail')); // Mail erstellen $mail = array('body' => utf8_decode($bodyText), 'to' => $to, 'subject' => 'ALLE ZIELE-Weiterempfehlung'); // Mail versenden $this->sendMail($mail); // View verarbeiten $this->render('empfehlen-success'); } /** * Sends an email using the application configuration * * @param $mail array mail settings */ public function sendMail($mail) { $this->loadConfig(); $map = array('from' => 'sender', 'from_name' => '', 'to' => 'receiver', 'to_name' => ''); foreach ($map as $config => $default) { if (!isset($mail[$config])) { $mail[$config] = $default !== '' ? $this->mailConfig[$default] : $default; } } $mailKeys = array('body', 'from', 'from_name', 'to', 'to_name', 'subject'); $this->checkConfig($mail, $mailKeys); $transport = new Zend_Mail_Transport_Smtp($this->mailConfig['server'], $this->mailConfig['credential']); $mailObj = new Zend_Mail(); $mailObj->setBodyText($mail['body']) ->setFrom($mail['from'], $mail['from_name']) ->addTo($mail['to'], $mail['to_name']) ->setSubject($mail['subject']) ->send($transport); } /** * Load Mail configuration section from application.ini * and verify all required settings are present */ private function loadConfig() { $options = $this->getInvokeArg('bootstrap')->getOptions(); if (!($options && isset($options['mail']))) { die ('Configuration section mail is missing.'); } $config = $options['mail']; $configKeys = array('server', 'credential' => array('auth', 'username', 'password'), 'sender', 'receiver'); $this->checkConfig($config, $configKeys); $this->mailConfig = $config; } /** * Test configuration array against the required array keys * * @param $config Configuration array * @param $required Required array keys */ private function checkConfig($config, $required) { if (!is_array($config) || !is_array($required)) { die('Missing Parameter'); } foreach ($required as $key => $sub) { if (is_numeric($key)) { unset($required[$key]); $required[$sub] = ''; } } if (($missing = array_diff_key($required, $config)) && count($missing) > 0) { die('Configuration Keys ' . implode(', ', array_keys($missing)) . ' are missing.'); } foreach ($required as $key => $subkeys) { if (is_array($subkeys)) { $this->checkConfig($config[$key], $subkeys); } } } }