Exemple #1
0
 public function passwordAction()
 {
     $request = $this->getRequest();
     $translator = Shineisp_Registry::getInstance()->Zend_Translate;
     if ($request->isPost()) {
         $email = $request->getParam('account');
         $customer = Customers::findbyemail($email, "email, password, language_id", true);
         if (isset($customer[0]) && is_numeric($customer[0]['customer_id'])) {
             // generate key
             $resetKey = Customers::generateResetPasswordKey($customer[0]['customer_id']);
         }
         if (count($customer) > 0 && !empty($resetKey)) {
             Shineisp_Commons_Utilities::sendEmailTemplate($customer[0]['email'], 'password_reset_link', array('link' => "http://" . $_SERVER['HTTP_HOST'] . "/index/resetpwd/id/" . $resetKey, ':shineisp:' => $customer), null, null, null, null, $customer[0]['language_id']);
             $this->view->mextype = "success";
             $this->view->mex = $translator->translate('Your password has been sent. Please click on the link contained in the email.');
         } else {
             $this->view->mextype = "alert";
             $this->view->mex = $translator->translate('User not found. Please check your credentials.');
         }
     }
     return $this->_helper->viewRenderer('password');
 }
Exemple #2
0
 /**
  * SendEmail
  * Smtp Configuration.
  * If you would like to use the smtp authentication, you have to add 
  * the parameters in the Setting Module of the Control Panel
  * 
  * @param string $from
  * @param string or array $to
  * @param string $bcc
  * @param string $subject
  * @param string $body
  * @param string $html
  * @param string $inreplyto
  * @param string/array $attachments
  * @return boolean|multitype:unknown NULL
  */
 public static function SendEmail($from, $to, $bcc = NULL, $subject, $body, $html = false, $inreplyto = NULL, $attachments = NULL, $replyto = NULL, $cc = null)
 {
     $transport = null;
     $config = array();
     $host = Settings::findbyParam('smtp_host');
     if (!empty($host)) {
         $username = Settings::findbyParam('smtp_user');
         $password = Settings::findbyParam('smtp_password');
         $port = Settings::findbyParam('smtp_port');
         $port = !empty($port) ? $port : 25;
         if (!empty($username) && !empty($password)) {
             $config = array('auth' => 'login', 'username' => $username, 'password' => $password, 'port' => $port);
         }
         $transport = new Zend_Mail_Transport_Smtp($host, $config);
     }
     $mail = new Zend_Mail('UTF-8');
     $mail->setHeaderEncoding(Zend_Mime::ENCODING_BASE64);
     if (!empty($attachments)) {
         if (is_array($attachments)) {
             foreach ($attachments as $attachment) {
                 if (file_exists($attachment)) {
                     $filename = basename($attachment);
                     // Get the content of the file
                     $content = file_get_contents($attachment);
                     // Create the attachment
                     $zend_attachment = new Zend_Mime_Part($content);
                     $zend_attachment->disposition = Zend_Mime::DISPOSITION_ATTACHMENT;
                     $zend_attachment->encoding = Zend_Mime::ENCODING_BASE64;
                     $zend_attachment->filename = $filename;
                     $mail->addAttachment($zend_attachment);
                 }
             }
         } else {
             if (file_exists($attachments)) {
                 $filename = basename($attachments);
                 // Get the content of the file
                 $content = file_get_contents($attachments);
                 // Create the attachment
                 $zend_attachment = new Zend_Mime_Part($content);
                 $zend_attachment->disposition = Zend_Mime::DISPOSITION_ATTACHMENT;
                 $zend_attachment->encoding = Zend_Mime::ENCODING_BASE64;
                 $zend_attachment->filename = $filename;
                 $mail->addAttachment($zend_attachment);
             }
         }
     }
     if (!empty($inreplyto)) {
         $mail->addHeader("In-Reply-To", $inreplyto);
     }
     if (!empty($replyto)) {
         $mail->setReplyTo($replyto);
     }
     // If the body of the message contains the HTML tags
     // we have to override the $html variable in order to send the html message by email
     if (self::isHtml($body)) {
         $html = true;
     }
     if ($html) {
         $mail->setBodyHtml($body, null, Zend_Mime::ENCODING_8BIT);
     } else {
         $mail->setBodyText($body);
     }
     if (is_array($from)) {
         $mail->setFrom($from['email'], $from['name']);
     } else {
         $mail->setFrom($from);
     }
     // If the $to is a group of emails addresses
     if (is_array($to)) {
         foreach ($to as $recipient) {
             $mail->addTo($recipient);
         }
     } else {
         $mail->addTo($to);
     }
     if (!empty($bcc)) {
         if (is_array($bcc) && count($bcc) > 0) {
             foreach ($bcc as $b) {
                 $mail->addBcc($b);
             }
         } else {
             $mail->addBcc($bcc);
         }
     }
     if (!empty($cc)) {
         if (is_array($cc) && count($cc) > 0) {
             foreach ($cc as $c) {
                 $mail->addCc($c);
             }
         } else {
             $mail->addCc($cc);
         }
     }
     $mail->setSubject($subject);
     try {
         $mail->send($transport);
         // All good, log to DB
         if (is_array($to)) {
             foreach ($to as $recipient) {
                 // get customer_id
                 $Customers = Customers::findbyemail($recipient);
                 if (is_object($Customers) && is_object($Customers->{0}) && isset($Customers->{0}->customer_id)) {
                     $customerId = $Customers->{0}->customer_id;
                 }
                 if (EmailsTemplatesSends::saveIt($customerId, $from, $recipient, $subject, $cc, $bcc, $html, $body)) {
                     Shineisp_Commons_Utilities::log("An email has been sent to {$recipient}", 'notice.log');
                     // log the data
                 }
             }
         } else {
             // get customer_id
             $Customers = Customers::findbyemail($to);
             if (is_object($Customers) && is_object($Customers->{0}) && isset($Customers->{0}->customer_id)) {
                 $customerId = $Customers->{0}->customer_id;
             }
             if (EmailsTemplatesSends::saveIt($customerId, $from, $to, $subject, $cc, $bcc, $html, $body)) {
                 Shineisp_Commons_Utilities::log("An email has been sent to {$to}", 'notice.log');
                 // log the data
             }
         }
         return true;
     } catch (Exception $e) {
         // log the data
         Shineisp_Commons_Utilities::log($e->getMessage());
         return array('email' => $to, 'message' => $e->getMessage());
     }
     return false;
 }