/** * * @param type $options * $options['html_message']; * $options['text_message']; * $options['subject']; * $options['from']; * $options['to']; * $options['cc']; * $options['bcc']; * @return type boolien */ public static function sendMail($options = array()) { $return = false; /** * Data preparation */ $emailer = new \Zf2mail\Controller\EmailersController(); $siteurl = $emailer->siteURL(); $predefined_signature = "ZF2Email"; $message_type = empty($options['message_type']) ? 'html' : $options['message_type']; $message = empty($options[$message_type . '_message']) ? '' : $options[$message_type . '_message']; $signature = empty($options['signature']) ? '<br><br>' . $predefined_signature : $options['signature']; $footer = empty($options['footer']) ? '' : $options['footer']; if (!empty($options['to'])) { if (is_array($options['to'])) { $to = implode(', ', $options['to']); } else { $to = $options['to']; } } if (!empty($options['cc'])) { if (is_array($options['cc'])) { $cc = implode(', ', $options['cc']); } else { $cc = $options['cc']; } } $bcc = empty($options['bcc']) ? '' : implode(', ', $options['bcc']); $from = empty($options['from']) ? '*****@*****.**' : trim($options['from']); $form_name = empty($options['from_name']) ? 'Your Domain' : trim($options['from_name']); $subject = empty($options['subject']) ? '' : trim($options['subject']); $returnpath = "-f" . $from; if (!empty($message)) { $message = $message . $signature . $footer; $headers = "MIME-Version: 1.0" . "\r\n"; $headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n"; $headers .= 'From: ' . $form_name . ' <' . $from . '>' . "\r\n"; if (!empty($cc)) { $headers .= 'cc: ' . $cc . '' . "\r\n"; } if (!empty($bcc)) { $headers .= 'bcc: ' . $bcc . ' ' . "\r\n"; } $return = mail($to, $subject, $message, $headers, $returnpath); } return $return; }
public function changePasswordAction() { $emailer = new \Zf2mail\Controller\EmailersController(); $id = (int) $this->getCurrentUser()->id; $users = $this->getUsersTable()->getUsers($id); $form = new ChangePasswordForm(); $form->setValidationGroup('id'); $form->bind($users); $request = $this->getRequest(); if ($request->isPost()) { $users = new Users(); $form->setInputFilter($users->getInputFilter()); $formData = $request->getPost(); $valid = true; /** * Check whether userid is exist */ $usersobj = $this->getUsersTable()->getUsers($formData['id']); if (empty($usersobj) || $formData['id'] != $id) { $valid = false; $this->error[0] = array('error' => $this->message->unauthorizedUser); } /** * Check whether password is valid */ if (MD5($formData['cpassword']) != $usersobj->password) { $valid = false; $this->error[0] = array('error' => $this->message->unauthorizedPassword); } if ($formData['password'] != $formData['repassword']) { $valid = false; $this->error[0] = array('error' => $this->message->passwordNotMatch); } if (strlen($formData['password']) < 6) { $valid = false; $this->error[0] = array('error' => $this->message->smallPassword); } if (empty($usersobj->email)) { $valid = false; $this->error[0] = array('error' => $this->message->emptyUsername); } $form->setData($formData); $form->setValidationGroup('id', 'password'); if ($form->isValid()) { if ($valid) { $body = "Hi " . trim($usersobj->name) . ",<br><br>Your password has been changed. <br /><br>\r\n\r\nGo here: <a href='" . $emailer->siteURL() . "'>" . $emailer->siteURL() . "</a><br />\r\n\r\nIf you have any questions, please do not hesitate to contact us at <a href=\"mailto:support@yourdomain.com\">support@yourdomain.com</a>."; $mailData = array('to' => $usersobj->email, 'subject' => "Password Changed successfully!", 'html_message' => $body); $mail = $emailer->sendMail($mailData); $users->exchangeArray($formData); $this->getUsersTable()->changePassword($users); $this->flashMessenger()->addMessage(array('success' => $this->message->changePassword)); if ($mail) { } else { $this->error[0] = array('error' => 'Can not sent email. Try again.'); } return $this->redirect()->toRoute('users/change-password'); } } // $this->error[0] = array('error' => 'Invalid Information'); } $vm = new ViewModel(array('flashMessages' => $this->flashMessenger()->getMessages(), 'form' => $form, 'error' => $this->error)); return $vm; }