public function indexAction() { $frmContact = new Contact_Form_Contact(); if ($this->_request->isPost() && $frmContact->isValid($_POST)) { // get the posted data $sender = $frmContact->getValue('name'); $email = $frmContact->getValue('email'); $subject = $frmContact->getValue('subject'); $message = $frmContact->getValue('message'); // load the template $htmlMessage = $this->view->partial('templates/default.phtml', $frmContact->getValues()); $mail = new Zend_Mail(); // configure and create the SMTP connection $config = array('auth' => 'login', 'username' => 'myusername', 'password' => 'password'); $transport = new Zend_Mail_Transport_Smtp('mail.server.com', $config); // set the subject $mail->setSubject($subject); // set the message's from address to the person who submitted the form $mail->setFrom($email, $sender); // for the sake of this example you can hardcode the recipient $mail->addTo('*****@*****.**', 'webmaster'); // add the file attachment $fileControl = $frmContact->getElement('attachment'); if ($fileControl->isUploaded()) { $attachmentName = $fileControl->getFileName(); $fileStream = file_get_contents($attachmentName); // create the attachment $attachment = $mail->createAttachment($fileStream); $attachment->filename = basename($attachmentName); } // it is important to provide a text only version in addition to the html message $mail->setBodyHtml($htmlMessage); $mail->setBodyText($message); //send the message, now using SMTP transport $result = $mail->send($transport); // inform the view with the status $this->view->messageProcessed = true; if ($result) { $this->view->sendError = false; } else { $this->view->sendError = true; } } $frmContact->setAction('/contact'); $frmContact->setMethod('post'); $this->view->form = $frmContact; }
/** * Edit action for contact controller * @throws Exception */ public function editAction() { // action body try { $translate = Zend_Registry::get('Zend_Translate'); $frmContact = new Contact_Form_Contact(); $frmContact->setAction($this->_request->getBaseUrl() . "/contact/contact/edit"); $id = $this->getRequest()->getParam('id', 0); $mdlContact = new Contact_Model_Contact(); $contact = $mdlContact->find($id)->current(); if (!$contact) { throw new Exception($translate->translate("LBL_ROW_NOT_FOUND")); } $mdlAccount = new Acl_Model_Account(); $accountList = $mdlAccount->getSimpleList(); $cbAccount = $frmContact->getElement('account_id'); foreach ($accountList as $account) { $cbAccount->addMultiOption($account->id, $account->email); } $mdlCategory = new Contact_Model_Category(); $categoryList = $mdlCategory->getSimpleList(); $cbCategory = $frmContact->getElement('category_id'); foreach ($categoryList as $category) { $cbCategory->addMultiOption($category->id, $category->title); } if ($this->getRequest()->isPost()) { if ($frmContact->isValid($_POST)) { $fileName = $contact->image; if ($frmContact->image->isUploaded()) { $ext = end(explode('.', $frmContact->image->getFileName())); $frmContact->image->addFilter('Rename', implode('_', array('cc', date('YmdHis'))) . '.' . $ext); $frmContact->image->receive(); $fileName = $frmContact->image->getFileName(null, false); chmod(DIR_MOD_CONTACT_IMG_UPLOADS . '/' . $fileName, 0755); $thumb = Zend_Layout::getMvcInstance()->getView()->thumbnail(DIR_MOD_CONTACT_IMG_UPLOADS . '/' . $fileName, 70, 70, DIR_MOD_CONTACT_THUMB_UPLOADS . '/', DIR_MOD_CONTACT_THUMB_UPLOADS); chmod($thumb, 0755); # eliminando original unlink(DIR_MOD_CONTACT_IMG_UPLOADS . '/' . $contact->image); $imgParts = explode('.', $contact->image); $nameImg = current($imgParts); $ext = end($imgParts); # eliminando thumb original unlink(DIR_MOD_CONTACT_THUMB_UPLOADS . '/' . $nameImg . '_thumb.' . $ext); } $contact->setFromArray($frmContact->getValues()); $contact->image = $fileName; $contact->save(); $this->_helper->flashMessenger->addMessage(array('type' => 'info', 'header' => '', 'message' => $translate->translate("LBL_ITEM_UPDATED_SUCCESSFULLY"))); $this->_helper->redirector("listregistered", "contact", "contact"); } } else { $frmContact->populate($contact->toArray()); $fields = array(); foreach ($frmContact->getElements() as $element) { $fields[] = $element->getName(); } $frmContact->addDisplayGroup($fields, 'form', array('legend' => "CONTACT_EDIT")); } $this->view->frmContact = $frmContact; } catch (Exception $e) { $this->_helper->flashMessenger->addMessage(array('type' => 'error', 'header' => '', 'message' => $e->getMessage())); $this->_helper->redirector("listregistered", "contact", "contact"); } return; }