public function postAction() { if ($datas = $this->getRequest()->getPost()) { try { // Test les eventuelles erreurs $errors = array(); if (empty($datas['name'])) { $errors[] = $this->_('Your name'); } if (empty($datas['email']) or !Zend_Validate::is($datas['email'], 'emailAddress')) { $errors[] = $this->_('Your email'); } if (empty($datas['info'])) { $errors[] = $this->_('Your request'); } $contact = new Contact_Model_Contact(); $contact->find($this->getCurrentOptionValue()->getId(), 'value_id'); if (!$contact->getId()) { throw new Exception($this->_('An error occurred while sending your request. Please try again later.')); } $dest_email = $contact->getEmail(); $app_name = $this->getApplication()->getName(); $layout = $this->getLayout()->loadEmail('contact', 'send_email'); $layout->getPartial('content_email')->setData($datas); $content = $layout->render(); $mail = new Zend_Mail('UTF-8'); $mail->setBodyHtml($content); $mail->setFrom($datas['email'], $datas['name']); $mail->addTo($dest_email, $app_name); $mail->setSubject($this->_("Message from your app %s", $app_name)); $mail->send(); if (!empty($errors)) { $message = $this->_('Please enter properly the following fields: <br />'); $message .= join('<br />', $errors); $html = array('error' => 1, 'message' => $message); } else { $html = array('success' => 1); } } catch (Exception $e) { $html = array('error' => 1, 'message' => $e->getMessage()); } $this->_sendHtml($html); } }
public function postAction() { if ($data = Zend_Json::decode($this->getRequest()->getRawBody())) { try { if (empty($data['email'])) { throw new Exception($this->_('Please enter your email address')); } if (!Zend_Validate::is($data['email'], 'EmailAddress')) { throw new Exception($this->_('Please enter a valid email address')); } $customer = new Customer_Model_Customer(); $customer->find(array('email' => $data['email'], "app_id" => $this->getApplication()->getId())); if (!$customer->getId()) { throw new Exception("Your email address does not exist"); } $admin_email = null; $password = Core_Model_Lib_String::generate(8); $contact = new Contact_Model_Contact(); $contact_page = $this->getApplication()->getPage('contact'); if ($contact_page->getId()) { $contact->find($contact_page->getId(), 'value_id'); $admin_email = $contact->getEmail(); } $customer->setPassword($password)->save(); $sender = 'no-reply@' . Core_Model_Lib_String::format($this->getApplication()->getName(), true) . '.com'; $layout = $this->getLayout()->loadEmail('customer', 'forgot_password'); $layout->getPartial('content_email')->setCustomer($customer)->setPassword($password)->setAdminEmail($admin_email)->setApp($this->getApplication()->getName()); $content = $layout->render(); $mail = new Zend_Mail('UTF-8'); $mail->setBodyHtml($content); $mail->setFrom($sender, $this->getApplication()->getName()); $mail->addTo($customer->getEmail(), $customer->getName()); $mail->setSubject($this->_('%s - Your new password', $this->getApplication()->getName())); $mail->send(); $html = array("success" => 1, "message" => $this->_("Your new password has been sent to the entered email address")); } catch (Exception $e) { $html = array('error' => 1, 'message' => $e->getMessage()); } $this->_sendHtml($html); } return $this; }
protected function _sendNewAccountEmail($customer, $password) { $admin_email = null; $contact = new Contact_Model_Contact(); $contact_page = $this->getApplication()->getPage('contact'); $sender = 'no-reply@' . Core_Model_Lib_String::format($this->getApplication()->getName(), true) . '.com'; if ($contact_page->getId()) { $contact->find($contact_page->getId(), 'value_id'); $admin_email = $contact->getEmail(); } $layout = $this->getLayout()->loadEmail('customer', 'create_account'); $layout->getPartial('content_email')->setCustomer($customer)->setPassword($password)->setAdminEmail($admin_email)->setApp($this->getApplication()->getName()); $content = $layout->render(); $mail = new Zend_Mail('UTF-8'); $mail->setBodyHtml($content); $mail->setFrom($sender, $this->getApplication()->getName()); $mail->addTo($customer->getEmail(), $customer->getName()); $mail->setSubject($this->_('%s - Account creation', $this->getApplication()->getName())); $mail->send(); return $this; }