コード例 #1
0
 public function sendEmail($from, $to, $cc, $subject, $body, $attachmentFilename)
 {
     $message = new Message();
     $message->setFrom($from);
     $message->setTo($to);
     $message->setCc($cc);
     $message->setSubject($subject);
     $mimeMessage = new \Zend\Mime\Message();
     $part = new \Zend\Mime\Part($body);
     $part->setType(Mime::TYPE_TEXT);
     $part->setCharset('UTF-8');
     $mimeMessage->addPart($part);
     $part = new \Zend\Mime\Part('<p>' . $body . '<p>');
     $part->setType(Mime::TYPE_HTML);
     $part->setCharset('UTF-8');
     $mimeMessage->addPart($part);
     $part = new \Zend\Mime\Part($body);
     $part->setType(Mime::TYPE_OCTETSTREAM);
     $part->setEncoding(Mime::ENCODING_BASE64);
     $part->setFileName($attachmentFilename);
     $part->setDisposition(Mime::DISPOSITION_ATTACHMENT);
     $mimeMessage->addPart($part);
     $message->setBody($mimeMessage);
     $this->transport->send($message);
     $this->debugSection('ZendMailer', $subject . ' ' . $from . ' -> ' . $to);
 }
コード例 #2
0
ファイル: EmailAction.php プロジェクト: rjsmelo/tiki
 function execute(JitFilter $data)
 {
     require_once 'lib/mail/maillib.php';
     try {
         $mail = tiki_get_admin_mail();
         if ($replyto = $data->replyto->email()) {
             $mail->setReplyTo($replyto);
         }
         foreach ($data->to->email() as $to) {
             $mail->addTo($this->stripNp($to));
         }
         foreach ($data->cc->email() as $cc) {
             $mail->addCc($this->stripNp($cc));
         }
         foreach ($data->bcc->email() as $bcc) {
             $mail->addBcc($this->stripNp($bcc));
         }
         $content = $this->parse($data->content->none());
         $subject = $this->parse($data->subject->text());
         $mail->setSubject(strip_tags($subject));
         $bodyPart = new \Zend\Mime\Message();
         $bodyMessage = new \Zend\Mime\Part($content);
         $bodyMessage->type = \Zend\Mime\Mime::TYPE_HTML;
         $bodyPart->setParts(array($bodyMessage));
         $mail->setBody($bodyPart);
         tiki_send_email($mail);
         return true;
     } catch (Exception $e) {
         return false;
     }
 }
コード例 #3
0
 /**
  * Creates a new user
  * @param \Zend\Db\Adapter\Adapter $db
  * @param type $login
  * @param type $password
  * @return \login\user\User
  */
 public static function createLoginInstance(\Zend\Db\Adapter\Adapter $db, $login, $password)
 {
     $user = self::getLoginInstance($db, $login);
     if (is_object($user) && $user->getData('username') != '') {
         throw new \Exception('Username already used ' . $login, 1409011238);
     }
     $adminColl = new \login\user\LoginColl($db);
     $adminColl->loadAll(array('role_id' => 3));
     $role_id = 3;
     $role_description = 'User';
     $active = 0;
     if ($adminColl->count() == 0) {
         $role_id = 1;
         $role_description = 'Administrator';
         $active = 1;
     }
     $profileRole = new \login\user\ProfileRole($db);
     $profileRole->loadFromId($role_id);
     if ($profileRole->getData('id') != $role_id) {
         $defaultRuleFile = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'install' . DIRECTORY_SEPARATOR . 'sql' . DIRECTORY_SEPARATOR . 'profile_role.sql';
         if (is_file($defaultRuleFile)) {
             $db->query(file_get_contents($defaultRuleFile), \Zend\Db\Adapter\Adapter::QUERY_MODE_EXECUTE);
         }
         $profileRole->loadFromId($role_id);
         if ($profileRole->getData('id') != $role_id) {
             $profileRole->setData(array('id' => $role_id, 'description' => $role_description));
             $profileRole->insert();
         }
     }
     $user = new \login\user\Login($db);
     $user->setData(array('username' => $login, 'password' => md5($password), 'creation_datetime' => date('Y-m-d H:i:s'), 'confirm_code' => md5(serialize($_SERVER) . time())));
     $user->insert();
     $profile = $user->getProfile();
     $profile->setData(array('role_id' => $role_id, 'active' => $active));
     $profile->update();
     ob_start();
     require $db->baseDir . DIRECTORY_SEPARATOR . 'mail' . DIRECTORY_SEPARATOR . 'register.php';
     $html = new \Zend\Mime\Part(ob_get_clean());
     $html->type = 'text/html';
     $body = new \Zend\Mime\Message();
     $body->setParts(array($html));
     $message = new \Zend\Mail\Message();
     $message->addTo($login)->addFrom($GLOBALS['config']->mail_from)->setSubject('Registrazione sul sito ' . $GLOBALS['config']->siteName)->setBody($body);
     $GLOBALS['transport']->send($message);
     if ($adminColl->count() > 0) {
         ob_start();
         require $db->baseDir . DIRECTORY_SEPARATOR . 'mail' . DIRECTORY_SEPARATOR . 'new_user.php';
         $html = new \Zend\Mime\Part(ob_get_clean());
         $html->type = 'text/html';
         $body = new \Zend\Mime\Message();
         $body->setParts(array($html));
         $message = new \Zend\Mail\Message();
         foreach ($adminColl->getItems() as $admin) {
             $message->addTo($admin->getData('username'));
         }
         $message->addFrom($GLOBALS['config']->mail_from)->setSubject('Registrazione sul sito ' . $GLOBALS['config']->siteName)->setBody($body);
         $GLOBALS['transport']->send($message);
     }
     return $user;
 }
コード例 #4
0
ファイル: MailService.php プロジェクト: kristjanAnd/SimpleIV
 public function send(SmtpTransport $transport = null, Message $message, array $attachments = array())
 {
     if ($transport == null) {
         $transport = new Sendmail();
     }
     $content = $message->getBody();
     $parts = $attachments;
     $parts = array();
     $bodyMessage = new \Zend\Mime\Message();
     $multiPartContentMessage = new \Zend\Mime\Message();
     $text = new Part(html_entity_decode(strip_tags(str_replace("<br />", "\n", $content))));
     $text->type = "text/plain";
     $text->encoding = Mime::ENCODING_QUOTEDPRINTABLE;
     $text->charset = 'UTF-8';
     $multiPartContentMessage->addPart($text);
     $html = new Part($content);
     $html->type = Mime::TYPE_HTML;
     $html->encoding = Mime::ENCODING_QUOTEDPRINTABLE;
     $html->charset = 'utf-8';
     $multiPartContentMessage->addPart($html);
     $multiPartContentMimePart = new Part($multiPartContentMessage->generateMessage());
     $multiPartContentMimePart->type = 'multipart/alternative;' . PHP_EOL . ' boundary="' . $multiPartContentMessage->getMime()->boundary() . '"';
     $bodyMessage->addPart($multiPartContentMimePart);
     foreach ($attachments as $attachment) {
         $bodyMessage->addPart($attachment);
     }
     $message->setBody($bodyMessage);
     $message->setEncoding("UTF-8");
     $transport->send($message);
 }
コード例 #5
0
ファイル: Email.php プロジェクト: KGalley/whathood
 public function send($subject, $messageBody)
 {
     $html = new \Zend\Mime\Part(nl2br($messageBody));
     $html->type = 'text/html';
     $body = new \Zend\Mime\Message();
     $body->setParts(array($html));
     $message = new Message();
     $message->addFrom($this->fromAddress, $this->fromName)->addTo($this->toAddress)->setSubject($subject);
     $message->setBody($body);
     $transport = $this->getTransport();
     $transport->send($message);
 }
コード例 #6
0
ファイル: Deliverer.php プロジェクト: railsphp/railsphp
 /**
  * Requires Fileinfo.
  */
 private function addAttachments()
 {
     if (class_exists('Finfo', false)) {
         $finfo = new \Finfo(FILEINFO_MIME_TYPE);
     } else {
         $finfo = false;
     }
     foreach ($this->mail->attachments as $filename => $attachment) {
         if (!is_array($attachment)) {
             throw new Exception\RuntimeException(sprintf("Attachments must be array, %s passed", gettype($attachment)));
         } elseif (!is_string($attachment['content']) && (!is_resource($attachment['content']) || !get_resource_type($attachment['content']) == 'stream')) {
             throw new Exception\RuntimeException(sprintf("Attachment content must be string or stream, %s passed", gettype($attachment['content'])));
         }
         $type = null;
         if (empty($attachment['mime_type']) && $finfo) {
             if (is_resource($attachment['content'])) {
                 $type = $finfo->buffer(stream_get_contents($attachment['content']));
                 rewind($attachment['content']);
             } else {
                 $type = $finfo->buffer($attachment['content']);
             }
         }
         $part = new Mime\Part($attachment['content']);
         if (empty($attachment['encoding'])) {
             $attachment['encoding'] = Mime\Mime::ENCODING_BASE64;
         }
         $part->encoding = $attachment['encoding'];
         if ($type) {
             $part->type = $type;
         }
         $part->disposition = !empty($attachment['inline']) ? Mime\Mime::DISPOSITION_INLINE : Mime\Mime::DISPOSITION_ATTACHMENT;
         $this->body->addPart($part);
     }
 }
コード例 #7
0
ファイル: Email.php プロジェクト: godentarek/whathood
 public function send($subject, $messageBody)
 {
     if (empty($subject)) {
         throw new \InvalidArgumentException("subject may not be empty");
     }
     $subject = sprintf("[%s] %s", substr(strtoupper(\Whathood\Util::environment()), 0, 4), $subject);
     $html = new \Zend\Mime\Part(nl2br($messageBody));
     $html->type = 'text/html';
     $body = new \Zend\Mime\Message();
     $body->setParts(array($html));
     $message = new Message();
     $message->addFrom($this->fromAddress, $this->fromName)->addTo($this->toAddress)->setSubject($subject);
     $message->setBody($body);
     $transport = $this->getTransport();
     if (\Whathood\Util::is_production()) {
         $transport->send($message);
     }
 }
コード例 #8
0
ファイル: Mail.php プロジェクト: trongle/book_zend2
 public function sendMail($email, $fullname, $linkActive)
 {
     $message = new \Zend\Mail\Message();
     $smtpOption = new SmtpOptions($this->_config);
     $message->setFrom($this->_config['connectionConfig']['username'], "bookStoreOnline");
     $message->setTo($email, $fullname);
     $message->setSubject("Kích hoạt tài khoản");
     $message->setEncoding("utf-8");
     //set HTML
     $content = new \Zend\Mime\Part("<p>Xin chào " . $fullname . "</p> \n\t\t\t<p>Bạn vừa đăng ký tài khoản tại website BookOnline,\n\t\t\tđể hoàn thành việc đăng ký bạn cui lòng <a href='" . $linkActive . "'>Click vào đây</a>\n\t\t\tđể kích hoạt tài khoản</p>");
     $content->type = Mime::TYPE_HTML;
     $content->charset = "utf-8";
     $mimeMessage = new \Zend\Mime\Message();
     $mimeMessage->setParts(array($content));
     $message->setBody($mimeMessage);
     $transport = new \Zend\Mail\Transport\Smtp($smtpOption);
     $transport->send($message);
 }
コード例 #9
0
ファイル: Mailler.php プロジェクト: amnarciso/bookcloud
 function send($to, $subject, $html, $ical = null)
 {
     $message = new Message();
     $message->addTo($to)->addFrom('*****@*****.**')->setSubject($subject);
     $bodyPart = new \Zend\Mime\Message();
     $bodyMessage = new \Zend\Mime\Part($html);
     $bodyMessage->type = 'text/html';
     $parts = array($bodyMessage);
     if ($ical) {
         $icalMessage = new \Zend\Mime\Part($ical);
         $icalMessage->type = 'text/calendar';
         $parts = array_merge($parts, array($icalMessage));
     }
     $bodyPart->setParts($parts);
     $message->setBody($bodyPart);
     $message->setEncoding('UTF-8');
     $this->transport->send($message);
 }
コード例 #10
0
ファイル: Mandrill.php プロジェクト: CatoTH/Stadtratsantraege
 /**
  * @param string $subject
  * @param string $plain
  * @param string $html
  * @param string $messageId
  *
  * @return \Zend\Mail\Message
  */
 public function createMessage($subject, $plain, $html, $messageId)
 {
     $mail = $this->getMessageClass();
     $mail->setFrom(\Yii::$app->params['mailFromEmail'], \Yii::$app->params['mailFromName']);
     $mail->setSubject($subject);
     $mail->setEncoding('UTF-8');
     $mId = new \Zend\Mail\Header\MessageId();
     $mId->setId($messageId);
     $mail->getHeaders()->addHeader($mId);
     if ($html == '') {
         $mail->setBody($plain);
         $content = new \Zend\Mail\Header\ContentType();
         $content->setType('text/plain');
         $content->addParameter('charset', 'UTF-8');
         $mail->getHeaders()->addHeader($content);
     } else {
         $html = '<!DOCTYPE html><html>
         <head><meta charset="utf-8"><title>' . Html::encode($subject) . '</title>
         </head><body>' . $html . '</body></html>';
         $converter = new \TijsVerkoyen\CssToInlineStyles\CssToInlineStyles($html);
         $converter->setStripOriginalStyleTags(true);
         $converter->setUseInlineStylesBlock(true);
         $converter->setEncoding('UTF-8');
         $converter->setCleanup(false);
         $converter->setExcludeMediaQueries(true);
         $contentHtml = $converter->convert();
         $contentHtml = preg_replace("/ data\\-[a-z0-9_-]+=\"[^\"]*\"/siu", "", $contentHtml);
         $textPart = new \Zend\Mime\Part($plain);
         $textPart->type = 'text/plain';
         $textPart->charset = 'UTF-8';
         $htmlPart = new \Zend\Mime\Part($contentHtml);
         $htmlPart->type = 'text/html';
         $htmlPart->charset = 'UTF-8';
         $mimem = new \Zend\Mime\Message();
         $mimem->setParts([$textPart, $htmlPart]);
         $mail->setBody($mimem);
         /** @var ContentType $contentType */
         $contentType = $mail->getHeaders()->get('content-type');
         $contentType->setType('multipart/alternative');
     }
     return $mail;
 }
コード例 #11
0
ファイル: Service.php プロジェクト: cobyl/ppmodulemailer
 /**
  * @param string $queue_name
  * @param string $to
  * @param string $subject
  * @param string $body
  * @param null $from
  * @param true $html
  */
 public function addMail($queue_name, $to, $subject, $body, $from = null, $html = false)
 {
     $message = new \Zend\Mail\Message();
     $message->setTo($to);
     $message->setSubject($this->translate ? $this->translate->translate($subject) : $subject);
     if ($html) {
         $bodyPart = new \Zend\Mime\Message();
         $bodyMessage = new \Zend\Mime\Part($body);
         $bodyMessage->type = 'text/html';
         $bodyPart->setParts(array($bodyMessage));
         $message->setBody($bodyPart);
     } else {
         $message->setBody($body);
     }
     $message->setEncoding("UTF-8");
     if ($from) {
         $message->setFrom($from);
     } else {
         $message->setFrom($this->config['default_from']);
     }
     $this->table->add($queue_name, $message);
 }
コード例 #12
0
 /**
  * @see \BoilerAppMessenger\Message\MessageTransporterInterface::sendMessage()
  * @param \BoilerAppMessenger\Message\Message $oMessage
  * @throws \UnexpectedValueException
  * @return \BoilerAppMessenger\Media\Mail\MailMessageTransporter
  */
 public function sendMessage(\BoilerAppMessenger\Message\Message $oMessage)
 {
     //Adapt message
     $oAdaptedMessage = new \Zend\Mail\Message();
     $oAdaptedMessage->setEncoding('UTF-8');
     //From Sender
     $oFrom = $oMessage->getFrom();
     if ($oFrom instanceof \BoilerAppMessenger\Media\Mail\MailMessageUserInterface) {
         $oAdaptedMessage->setFrom($oFrom->getUserEmail(), $oFrom->getUserDisplayName());
     } else {
         throw new \UnexpectedValueException(sprintf('"From" sender expects an instance of \\BoilerAppMessenger\\Mail\\MailMessageUserInterface, "%s" given', is_scalar($oFrom) ? $oFrom : (is_object($oFrom) ? get_class($oFrom) : gettype($oFrom))));
     }
     //To Recipiants
     foreach ($oMessage->getTo() as $oTo) {
         if ($oTo instanceof \BoilerAppMessenger\Media\Mail\MailMessageUserInterface) {
             $oAdaptedMessage->addTo($oTo->getUserEmail(), $oTo->getUserDisplayName());
         } else {
             throw new \UnexpectedValueException(sprintf('"To" Recipiant expects an instance of \\BoilerAppMessenger\\Mail\\MailMessageUserInterface, "%s" given', is_scalar($oTo) ? $oTo : (is_object($oTo) ? get_class($oTo) : gettype($oTo))));
         }
     }
     //Subject
     $oAdaptedMessage->setSubject($oMessage->getSubject());
     //Reset attachments
     $this->attachments = array();
     foreach ($oMessage->getAttachments() as $sAttachmentFilePath) {
         $this->addFileAttachment($sAttachmentFilePath);
     }
     //Body
     $oBodyPart = new \Zend\Mime\Part(preg_replace_callback('/src="([^"]+)"/', array($this, 'processImageSrc'), $this->getMessageRenderer()->renderMessageBody($oMessage)));
     $oBodyPart->type = \Zend\Mime\Mime::TYPE_HTML;
     $oBody = new \Zend\Mime\Message();
     $oBody->setParts(array_merge(array($oBodyPart), $this->attachments));
     $oAdaptedMessage->setBody($oBody)->setEncoding('UTF-8');
     //Send message
     $this->getMailTransporter()->send($oAdaptedMessage);
     return $this;
 }
コード例 #13
0
ファイル: SESAdapter.php プロジェクト: milqmedia/mq-mailqueue
 public function sendEmailsFromQueue($developmentMode = false)
 {
     $transport = $this->serviceManager->get('SlmMail\\Mail\\Transport\\SesTransport');
     $entity = new $this->config['database']['entity']();
     $tableName = $this->entityManager->getClassMetadata(get_class($entity))->getTableName();
     $dql = 'SELECT m FROM ' . $this->config['database']['entity'] . ' m WHERE m.send = 0 AND m.scheduleDate <= :now ORDER BY m.prio, m.createDate DESC';
     $query = $this->entityManager->createQuery($dql)->setParameter('now', date('Y-m-d H:i:s'))->setMaxResults($this->config['numberOfEmailsPerRun']);
     $queue = $query->getResult();
     foreach ($queue as $mail) {
         // In development mode we only send emails to predefined email addresses to prevent "strange" unrequested
         // emails to users.
         if ($developmentMode === true && !in_array($mail->getRecipientEmail(), $this->config['developmentEmails'])) {
             $this->entityManager->getConnection()->update($tableName, array('send' => 1), array('id' => $mail->getId()));
             continue;
         }
         $message = new \Zend\Mail\Message();
         $message->addFrom($mail->getSenderEmail(), $mail->getSenderName())->addTo($mail->getRecipientEmail(), $mail->getRecipientName())->setSubject($mail->getSubject());
         if (trim($mail->getBodyHTML()) !== '') {
             $bodyPart = new \Zend\Mime\Message();
             $bodyMessage = new \Zend\Mime\Part($mail->getBodyHTML());
             $bodyMessage->type = 'text/html';
             $bodyPart->setParts(array($bodyMessage));
             $message->setBody($bodyPart);
             $message->setEncoding('UTF-8');
         } else {
             $message->setBody($mail->getBodyText());
         }
         try {
             $transport->send($message);
             $this->entityManager->getConnection()->update($tableName, array('send' => 1, 'sendDate' => date('Y-m-d H:i:s')), array('id' => $mail->getId()));
         } catch (\Exception $e) {
             $this->entityManager->getConnection()->update($tableName, array('send' => 2, 'error' => $e->getMessage()), array('id' => $mail->getId()));
             $this->queueNewMessage('MailAdmin', $this->config['adminEmail'], $e->getMessage(), $e->getMessage(), 'MailQueue Error', 9);
         }
     }
 }
コード例 #14
0
 public function forgotpasswordAction()
 {
     $this->layout('layout/bags');
     $getuser = $this->getuserAction();
     //var_dump($getuser);
     $this->layout()->getuser = $getuser;
     if ($this->request->isPost()) {
         $email = addslashes(trim($this->params()->fromPost('email')));
         $check = $this->getAdminTable()->checkemail($email);
         if ($check == 1) {
             $pass = $this->getAdminTable()->generateRandomString();
             $bcrypt = new Bcrypt();
             $endpass = $bcrypt->create($pass);
             $this->getAdminTable()->forgotpass($email, $endpass);
             $message = array();
             $message[] = "";
             $message[] = "------ Thông tin mật khẩu-------";
             $message[] = "Mật khảu hiện tại của bạn là : " . $pass;
             $message[] = "";
             $message[] = "Hãy đăng nhập và thay đổi mật khẩu.";
             $message[] = "";
             $message[] = WEBPATH . "/loginmaster";
             $message[] = "---------------------------------";
             $textPart = new \Zend\Mime\Part(implode("\r\n", $message));
             $textPart->type = "text/plain";
             $body = new \Zend\Mime\Message();
             $body->setParts(array($textPart));
             $sendmail = new Message();
             $sendmail->setTo($email);
             $sendmail->setFrom("*****@*****.**");
             $sendmail->setEncoding("UTF-8");
             $sendmail->setSubject("Yêu Cầu Thay Đổi Mật Khẩu Tại ." . WEBPATH);
             $sendmail->setBody($body);
             $transport = new SmtpTransport();
             $option = new SmtpOptions(array('name' => 'localhost', 'host' => '166.62.28.97', 'port' => '25', 'connection_class' => 'login', 'connection_config' => array('username' => '*****@*****.**', 'password' => 'esell@Ellacy1990', 'ssl' => 'tls')));
             $transport->setOptions($option);
             $transport->send($sendmail);
             $alert = '<p class="alert alert-success">A new password has been sent to e-mail us your check for information email accounts committee .</p>';
             return array('alert' => $alert);
         } else {
             $alert = '<p class="alert alert-warning">This email is not registered</p>';
             return array('alert' => $alert);
         }
     }
 }
コード例 #15
0
ファイル: tikimaillib.php プロジェクト: rjsmelo/tiki
 protected function convertBodyToMime($text)
 {
     $textPart = new Zend\Mime\Part($text);
     $textPart->setType(Zend\Mime\Mime::TYPE_TEXT);
     $newBody = new Zend\Mime\Message();
     $newBody->addPart($textPart);
     $this->mail->setBody($newBody);
 }
コード例 #16
0
 /**
  * @description creates a recover form and processes said form.
  * @return ViewModel
  */
 public function recoverAction()
 {
     if ($this->authService->hasIdentity()) {
         return $this->redirect()->toRoute($this->config['onLoginRedirectRouteName']);
     }
     $request = $this->getRequest();
     if ($request->isPost()) {
         $this->recoverForm->setInputFilter($this->recoverFormValidator->getInputFilter());
         $this->recoverForm->setData($request->getPost());
         if ($this->recoverForm->isValid()) {
             $recoverFormData = $this->recoverForm->getData();
             $identityProperty = $this->authService->getAdapter()->getOptions()->getIdentityProperty();
             $roleProperty = $this->config['acl']['roleProperty'];
             $userObject = $this->userService->setPasswordReset($recoverFormData['identity'], $identityProperty);
             if ($userObject) {
                 $getter = 'get' . ucfirst($this->config['userEmailAddressProperty']);
                 if (method_exists($userObject, $getter)) {
                     $emailAddress = $userObject->{$getter}();
                 } elseif (property_exists($userObject, $roleProperty)) {
                     $emailAddress = $userObject->{$identityProperty};
                 } else {
                     throw new \UnexpectedValueException(sprintf('Property (%s) in (%s) is not accessible. You should implement %s::%s()', $identityProperty, get_class($userObject), get_class($userObject), $getter));
                 }
                 $emailView = new ViewModel();
                 $emailView->setTemplate($this->config['viewPath']['emailTemplate'])->setVariables(array('user' => $userObject, 'identityProperty' => $identityProperty, 'identityValue' => $recoverFormData['identity'], 'email' => $emailAddress, 'config' => $this->config));
                 $emailContent = $this->viewRenderer->render($emailView);
                 if (!empty($this->config['viewPath']['emailLayout'])) {
                     $viewLayout = new \Zend\View\Model\ViewModel();
                     $viewLayout->setTemplate($this->config['viewPath']['emailLayout'])->setVariables(array('content' => $emailContent));
                     $emailContent = $this->viewRenderer->render($viewLayout);
                 }
                 $html = new Part($emailContent);
                 $html->type = "text/html";
                 $body = new \Zend\Mime\Message();
                 $body->setParts(array($html));
                 $message = new Message();
                 $message->setSubject($this->translator->translate($this->config['messages']['passwordResetEmailSubject']));
                 $fromEmail = isset($this->mailConfig['defaultFrom']) ? $this->mailConfig['defaultFrom'] : $this->mailTransport->getOptions()->getConnectionConfig()['username'];
                 $message->addFrom($fromEmail);
                 $message->addTo($emailAddress);
                 $message->setBody($body);
                 $this->mailTransport->send($message);
             }
         }
         $successMessage = $this->translator->translate($this->config['messages']['recoverSubmitSuccess']);
         if ($request->isXmlHttpRequest()) {
             $jsonResponse = new JsonModel(array('code' => 'recover-success', 'message' => $successMessage, 'success' => true));
             return $jsonResponse;
         } else {
             $this->flashMessenger()->addSuccessMessage($successMessage);
             return $this->redirect()->toRoute('recover');
         }
     }
     $viewModel = new ViewModel(array('form' => $this->recoverForm));
     if (empty($this->config['layoutName'])) {
         $viewModel->setTerminal(true);
     } else {
         $this->layout($this->config['layoutName']);
     }
     $viewModel->setTemplate($this->config['viewPath']['recover']);
     //'storefront/index/recover.phtml'
     return $viewModel;
 }
コード例 #17
0
ファイル: MailService.php プロジェクト: bitweb/mail
 public function send(Message $message, array $attachments = array())
 {
     if ($this->getConfiguration()->getSendAllMailsToBcc() !== null) {
         $message->addBcc($this->getConfiguration()->getSendAllMailsToBcc());
     }
     if ($this->getConfiguration()->getSendAllMailsTo() != null) {
         $message->setTo($this->getConfiguration()->getSendAllMailsTo());
     }
     $content = $message->getBody();
     $bodyMessage = new \Zend\Mime\Message();
     $multiPartContentMessage = new \Zend\Mime\Message();
     $text = new Part(strip_tags($content));
     $text->type = Mime::TYPE_TEXT;
     $text->encoding = Mime::ENCODING_QUOTEDPRINTABLE;
     $multiPartContentMessage->addPart($text);
     $html = new Part($content);
     $html->type = Mime::TYPE_HTML;
     $html->encoding = Mime::ENCODING_QUOTEDPRINTABLE;
     $html->charset = 'utf-8';
     $multiPartContentMessage->addPart($html);
     $multiPartContentMimePart = new Part($multiPartContentMessage->generateMessage());
     $multiPartContentMimePart->charset = 'UTF-8';
     $multiPartContentMimePart->type = 'multipart/alternative';
     $multiPartContentMimePart->boundary = $multiPartContentMessage->getMime()->boundary();
     $bodyMessage->addPart($multiPartContentMimePart);
     foreach ($attachments as $attachment) {
         $bodyMessage->addPart($attachment);
     }
     $message->setBody($bodyMessage);
     $message->setEncoding("UTF-8");
     $this->transport->send($message);
 }
コード例 #18
0
/**
 * Send an email to any email address
 *
 * @param mixed $from     Email address or string: "name <email>"
 * @param mixed $to       Email address or string: "name <email>"
 * @param string $subject The subject of the message
 * @param string $body    The message body
 * @param array  $params  Optional parameters
 * @return bool
 * @throws NotificationException
 */
function notifications_html_handler_send_email($from, $to, $subject, $body, array $params = null)
{
    $options = array('to' => $to, 'from' => $from, 'subject' => $subject, 'body' => $body, 'params' => $params, 'headers' => array("Content-Type" => "text/html; charset=UTF-8; format=flowed", "MIME-Version" => "1.0", "Content-Transfer-Encoding" => "8bit"));
    // $mail_params is passed as both params and return value. The former is for backwards
    // compatibility. The latter is so handlers can now alter the contents/headers of
    // the email by returning the array
    $options = elgg_trigger_plugin_hook('email', 'system', $options, $options);
    if (!is_array($options)) {
        // don't need null check: Handlers can't set a hook value to null!
        return (bool) $options;
    }
    try {
        if (empty($options['from'])) {
            $msg = "Missing a required parameter, '" . 'from' . "'";
            throw new \NotificationException($msg);
        }
        if (empty($options['to'])) {
            $msg = "Missing a required parameter, '" . 'to' . "'";
            throw new \NotificationException($msg);
        }
        $options['to'] = \Elgg\Mail\Address::fromString($options['to']);
        $options['from'] = \Elgg\Mail\Address::fromString($options['from']);
        $options['subject'] = elgg_strip_tags($options['subject']);
        $options['subject'] = html_entity_decode($options['subject'], ENT_QUOTES, 'UTF-8');
        // Sanitise subject by stripping line endings
        $options['subject'] = preg_replace("/(\r\n|\r|\n)/", " ", $options['subject']);
        $options['subject'] = elgg_get_excerpt(trim($options['subject'], 80));
        $message = new \Zend\Mail\Message();
        foreach ($options['headers'] as $headerName => $headerValue) {
            $message->getHeaders()->addHeaderLine($headerName, $headerValue);
        }
        $message->setEncoding('UTF-8');
        $message->addFrom($options['from']);
        $message->addTo($options['to']);
        $message->setSubject($options['subject']);
        $body = new Zend\Mime\Message();
        $html = new \Zend\Mime\Part($options['body']);
        $html->type = "text/html";
        $body->addPart($html);
        $files = elgg_extract('attachments', $options['params']);
        if (!empty($files) && is_array($files)) {
            foreach ($files as $file) {
                if (!$file instanceof \ElggFile) {
                    continue;
                }
                $attachment = new \Zend\Mime\Part(fopen($file->getFilenameOnFilestore(), 'r'));
                $attachment->type = $file->getMimeType() ?: $file->detectMimeType();
                $attachment->filename = $file->originalfilename ?: basename($file->getFilename());
                $attachment->disposition = Zend\Mime\Mime::DISPOSITION_ATTACHMENT;
                $attachment->encoding = Zend\Mime\Mime::ENCODING_BASE64;
                $body->addPart($attachment);
            }
        }
        $message->setBody($body);
        $transport = notifications_html_handler_get_transport();
        if (!$transport instanceof Zend\Mail\Transport\TransportInterface) {
            throw new \NotificationException("Invalid Email transport");
        }
        $transport->send($message);
    } catch (\Exception $e) {
        elgg_log($e->getMessage(), 'ERROR');
        return false;
    }
    return true;
}
コード例 #19
0
ファイル: Attacher.php プロジェクト: bix0r/Stjornvisi
 /**
  * @param string $trackerString
  * @return \Zend\Mail\Message
  */
 public function parse($trackerString = null)
 {
     //IF BODY
     //	if the body is not empty, the we can
     //	parse it through DOMDocument
     if (!empty($this->textBody)) {
         //MIME-MESSAGE
         //	first we need mime-message, that will
         //	hold all the parts (attachments)
         $mimeMessage = new \Zend\Mime\Message();
         //IMAGES
         //	then we convert the body string to DOMDocument
         //	object and extract all images from it
         $domDocument = new \DOMDocument('1.0', 'UTF-8');
         @$domDocument->loadHTML('<?xml encoding="utf-8" ?>' . $this->textBody);
         $images = $domDocument->getElementsByTagName('img');
         $parts = array();
         //LOOP IMAGES
         //	then for every image we find in body text, we extract
         //	the src, check it that is a real file and if so, convert
         //	it into a Part object which we add to the mime-message
         foreach ($images as $image) {
             /** @var $image \DOMElement */
             $realName = $image->getAttribute('src');
             $cleanName = $this->cleanName(preg_replace('/^.+[\\\\\\/]/', '', $realName));
             $templateImage = !$image->hasAttribute('template');
             if (!$image->hasAttribute('template')) {
                 $image->setAttribute('align', 'left');
                 $image->setAttribute('style', 'margin:0 10px 0 0;width:100%;max-width:100%');
             }
             if (is_file(getcwd() . '/public' . $realName)) {
                 //MIME
                 //	first for the MIME of the image
                 $finfo = new \finfo();
                 $mime = $finfo->file(getcwd() . '/public' . $realName, FILEINFO_MIME_TYPE);
                 $mime = $mime ? $mime : 'application/octet-stream';
                 //CID
                 //	the src attribute has to be changed to something simpler
                 //	and something that begins with 'cid:' then the ID of the
                 //	attachment gets the same value, that is how the html body
                 //	can reference an attachment as an image
                 $image->setAttribute('src', 'cid:' . $cleanName);
                 $fileContent = fopen(getcwd() . '/public' . $realName, 'r');
                 $attachment = new Part($fileContent);
                 $attachment->type = $mime;
                 $attachment->id = $cleanName;
                 $attachment->filename = $cleanName;
                 //$attachment->disposition = Mime::DISPOSITION_ATTACHMENT;
                 $attachment->disposition = Mime::DISPOSITION_INLINE;
                 // Setting the encoding is recommended for binary data
                 $attachment->encoding = Mime::ENCODING_BASE64;
                 //$mimeMessage->addPart( $attachment );
                 $parts[] = $attachment;
             }
         }
         //TRACKER IMAGE
         //	if there is a tracker string passed,
         //	we will set that as the SRC attribute of an IMG
         //	element, this is done to try to track if a user opens
         //	his/her mail.
         if ($trackerString) {
             $trackerImage = $domDocument->createElement('img');
             /** @var $trackerImage \DOMElement */
             $trackerImage->setAttribute('src', $trackerString);
             $trackerImage->setAttribute('height', 1);
             $trackerImage->setAttribute('width', 1);
             $domDocument->getElementsByTagName('body')->item(0)->appendChild($trackerImage);
         }
         //TEXT
         //	one part of the mime-message is the actual body-text
         //	which we treat like an attachment, that is: we create
         //	a part and attache it to them mime-message
         $text = new Part(preg_replace('/^<!DOCTYPE.+?>/', '', str_replace(array('<html>', '</html>', '<body>', '</body>', '<?xml encoding="utf-8" ?>'), array('', '', '', '', ''), $domDocument->saveHTML())));
         $text->type = Mime::TYPE_HTML;
         $text->charset = 'utf-8';
         //$mimeMessage->addPart( $text );
         $parts = array_merge(array($text), $parts);
         $mimeMessage->setParts($parts);
         $this->message->setBody($mimeMessage);
     }
     return $this->message;
 }
コード例 #20
0
ファイル: Zend2.php プロジェクト: aimeos/ai-zend2
 /**
  * Creates a mail message container of the given type for the mime parts.
  *
  * @param Zend\Mime\Part[] $parts List of mime parts that should be included in the container
  * @param string $type Mime type, e.g. "multipart/related" or "multipart/alternative"
  * @return \Zend\Mime\Part Container mime object
  */
 protected function createContainer(array $parts, $type)
 {
     $msg = new \Zend\Mime\Message();
     $msg->setParts($parts);
     $part = new \Zend\Mime\Part($msg->generateMessage());
     $part->encoding = \Zend\Mime\Mime::ENCODING_8BIT;
     $part->boundary = $msg->getMime()->boundary();
     $part->disposition = null;
     $part->charset = null;
     $part->type = $type;
     return $part;
 }
コード例 #21
0
ファイル: SlmAbstract.php プロジェクト: swissup/email
 protected function convertMailMessage($mail)
 {
     if (!$mail instanceof \Zend_Mail) {
         throw new \InvalidArgumentException('The message should be an instance of \\Zend_Mail');
     }
     //convert zend_mail1 to zend\mail\message
     // \Zend_Debug::dump($mail->getFrom());
     // \Zend_Debug::dump(get_class_methods($mail));
     // \Zend_Debug::dump($mail->getHeader('To'));
     // \Zend_Debug::dump($mail->getHeaders());
     $headers = new \Zend\Mail\Headers();
     $_headers = [];
     foreach ($mail->getHeaders() as $headerName => $values) {
         foreach ($values as $key => $value) {
             if ($key !== 'append') {
                 $_headers[$headerName][$key] = $value;
             }
         }
     }
     $headers->addHeaders($_headers);
     $headersEncoding = $mail->getHeaderEncoding();
     $headers->setEncoding($headersEncoding);
     $_message = new \Zend\Mail\Message();
     $_message->setHeaders($headers);
     $body = new \Zend\Mime\Message();
     $charset = $mail->getCharset();
     $text = $mail->getBodyText();
     if (!empty($text)) {
         if ($text instanceof \Zend_Mime_Part) {
             $part = new \Zend\Mime\Part($text->getContent());
             $part->encoding = $text->encoding;
             $part->type = $text->type;
             $part->charset = $text->charset;
         } elseif (is_string($text)) {
             $part = new \Zend\Mime\Part($text);
             $part->encoding = \Zend\Mime\Mime::ENCODING_QUOTEDPRINTABLE;
             $part->type = \Zend\Mime\Mime::TYPE_TEXT;
             $part->charset = $charset;
         }
         $body->addPart($part);
     }
     $html = $mail->getBodyHtml();
     if (!empty($html)) {
         if ($html instanceof \Zend_Mime_Part) {
             $part = new \Zend\Mime\Part($html->getContent());
             $part->encoding = $html->encoding;
             $part->type = $html->type;
             $part->charset = $html->charset;
         } elseif (is_string($html)) {
             $part = new \Zend\Mime\Part($html);
             $part->encoding = \Zend\Mime\Mime::ENCODING_QUOTEDPRINTABLE;
             $part->type = \Zend\Mime\Mime::TYPE_TEXT;
             $part->charset = $charset;
         }
         $body->addPart($part);
     }
     //@todo $mail->getParts() copy attachments
     $_message->setBody($body);
     // \Zend_Debug::dump($_message);
     // die;
     return $_message;
 }
コード例 #22
0
 public function changeemailAction()
 {
     $view = new ViewModel();
     $this->layout('layout/layout-portada2');
     $request = $this->getRequest();
     $form = new PasswordForm();
     if ($request->isPost()) {
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $mail = $this->params()->fromPost('va_email');
             try {
                 $results = $this->getClientesTable()->generarPassword($mail);
                 $usuario = $this->getClientesTable()->getUsuarioxEmail($mail);
                 //                    $mensajes='Este correo fue enviado con exito...';
                 $this->flashmessenger()->addMessage('Se le ha enviado un correo a la cuenta indicada, por favor seguir las instrucciones.');
             } catch (\Exception $e) {
                 //                    $mensajes='Este correo no esta registrado...';
                 $this->flashmessenger()->addMessage('Este correo no esta registrado.');
             }
             if ($results) {
                 $config = $this->getServiceLocator()->get('Config');
                 $bodyHtml = '<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml">
                                            <head>
                                            <meta http-equiv="Content-type" content="text/html;charset=UTF-8"/>
                                            </head>
                                            <body>
                                                 <div style="color: #7D7D7D"><br />
                                                 Hola ' . ucwords($usuario->va_nombre_cliente) . ',<br /><br />  
                                                 Para recuperar tu contraseña debes hacer <a href="' . $config['host']['base'] . '/?value=' . utf8_decode($results) . '">Clic Aquí</a><br /><br /> 
                                                 o copiar la siguiente url en su navegador:<br /><br />' . $config['host']['base'] . '/?value=' . utf8_decode($results) . '          
                                                  </div>
                                                  <br /><br /><br />
                                                  <img src="' . $config['host']['img'] . '/img/logo.png" title="listadelsabor.com"/>
                                            </body>
                                            </html>';
                 $message = new Message();
                 $message->addTo($mail)->addFrom('*****@*****.**', 'listadelsabor.com')->setSubject('Recuperación de contraseña');
                 $bodyPart = new \Zend\Mime\Message();
                 $bodyMessage = new \Zend\Mime\Part($bodyHtml);
                 $bodyMessage->type = 'text/html';
                 $bodyPart->setParts(array($bodyMessage));
                 $message->setBody($bodyPart);
                 $message->setEncoding('UTF-8');
                 $transport = $this->getServiceLocator()->get('mail.transport');
                 // new SendmailTransport();//$this->getServiceLocator('mail.transport')
                 $transport->send($message);
             }
             return $this->redirect()->toUrl('/cambio');
         } else {
             foreach ($form->getInputFilter()->getInvalidInput() as $error) {
                 $mensajes = $error->getMessages();
                 return new JsonModel(array('menssage' => $mensajes, 'success' => false));
                 exit;
             }
         }
     }
     $flashMessenger = $this->flashMessenger();
     if ($flashMessenger->hasMessages()) {
         $mensajes = $flashMessenger->getMessages();
         return new JsonModel(array('menssage' => $mensajes, 'success' => false));
         exit;
     }
     return array('form' => $form, 'mensaje' => $mensajes);
     return $view;
 }
コード例 #23
0
ファイル: nllib.php プロジェクト: linuxwhy/tiki-1
 private function get_edition_mail($editionId, $target, $is_html = null)
 {
     global $prefs, $base_url;
     static $mailcache = array();
     if (!isset($mailcache[$editionId])) {
         $tikilib = TikiLib::lib('tiki');
         $headerlib = TikiLib::lib('header');
         $info = $this->get_edition($editionId);
         $nl_info = $this->get_newsletter($info['nlId']);
         // build the html
         $beginHtml = '<body class="tiki_newsletters"><div id="tiki-center" class="clearfix content"><div class="wikitext">';
         $endHtml = '</div></div></body>';
         if ($is_html === null) {
             $is_html = $info['wysiwyg'] === 'y' && $prefs['wysiwyg_htmltowiki'] !== 'y';
             // parse as html if wysiwyg and not htmltowiki
         } else {
             $is_html = !empty($is_html);
         }
         if (stristr($info['data'], '<body') === false) {
             $html = "<html>{$beginHtml}" . $tikilib->parse_data($info['data'], array('absolute_links' => true, 'suppress_icons' => true, 'is_html' => $is_html)) . "{$endHtml}</html>";
         } else {
             $html = str_ireplace('<body>', $beginHtml, $info['data']);
             $html = str_ireplace('</body>', $endHtml, $html);
         }
         if ($nl_info['allowArticleClip'] == 'y' && $nl_info['autoArticleClip'] == 'y') {
             $articleClip = $this->clip_articles($nl_info['nlId']);
             $txtArticleClip = $this->generateTxtVersion($articleClip);
             $info['datatxt'] = str_replace('~~~articleclip~~~', $txtArticleClip, $info['datatxt']);
             $html = str_replace('~~~articleclip~~~', $articleClip, $html);
             if ($articleClip == '<div class="articleclip"></div>' && $nl_info['emptyClipBlocksSend'] == 'y') {
                 return '';
             }
         }
         if (stristr($html, '<base') === false) {
             if (stristr($html, '<head') === false) {
                 $themelib = TikiLib::lib('theme');
                 $news_cssfile = $themelib->get_theme_path($prefs['theme'], '', 'newsletter.css');
                 $news_cssfile_option = $themelib->get_theme_path($prefs['theme'], $prefs['theme_option'], 'newsletter.css');
                 $news_css = '';
                 if (!empty($news_cssfile)) {
                     $news_css .= $headerlib->minify_css($news_cssfile);
                 }
                 if (!empty($news_cssfile_option) && $news_cssfile_option !== $news_cssfile) {
                     $news_css .= $headerlib->minify_css($news_cssfile_option);
                 }
                 if (empty($news_css)) {
                     $news_css = $headerlib->get_all_css_content();
                 }
                 $news_head = "<html><head><base href=\"{$base_url}\" /><style type=\"text/css\">{$news_css}</style></head>";
                 $html = str_ireplace('<html>', $news_head, $html);
             } else {
                 $html = str_ireplace('<head>', "<head><base href=\"{$base_url}\" />", $html);
             }
         }
         $info['files'] = $this->get_edition_files($editionId);
         include_once 'lib/mail/maillib.php';
         /* @var Zend\Mail\Message $zmail */
         $zmail = tiki_get_admin_mail();
         $emailMimeParts = array();
         if (!empty($info['replyto'])) {
             $zmail->setReplyTo($info['replyto']);
         }
         foreach ($info['files'] as $f) {
             $fpath = isset($f['path']) ? $f['path'] : $prefs['tmpDir'] . '/newsletterfile-' . $f['filename'];
             $att = new Zend\Mime\Part(file_get_contents($fpath));
             $att->filename = $f['name'];
             $att->type = $f['type'];
             $att->encoding = Zend\Mime\Mime::ENCODING_BASE64;
             $emailMimeParts[] = $att;
         }
         $zmail->setSubject($info['subject']);
         $mailcache[$editionId] = array('zmail' => $zmail, 'text' => $info['datatxt'], 'html' => $html, 'unsubMsg' => $nl_info['unsubMsg'], 'nlId' => $nl_info['nlId']);
     }
     $cache = $mailcache[$editionId];
     $html = $cache['html'];
     $unsubmsg = '';
     if ($cache["unsubMsg"] == 'y' && !empty($target["code"])) {
         $unsubmsg = $this->get_unsub_msg($cache["nlId"], $target['email'], $target['language'], $target["code"], $target['user']);
         if (stristr($html, '</body>') === false) {
             $html .= $unsubmsg;
         } else {
             $html = str_replace("</body>", nl2br($unsubmsg) . "</body>", $html);
         }
     }
     $zmail = $cache['zmail'];
     $textPart = new Zend\Mime\Part($cache['text'] . strip_tags($unsubmsg));
     $textPart->setType(Zend\Mime\Mime::TYPE_TEXT);
     $emailMimeParts[] = $textPart;
     $htmlPart = new Zend\Mime\Part($html);
     $htmlPart->setType(Zend\Mime\Mime::TYPE_HTML);
     $emailMimeParts[] = $htmlPart;
     $emailBody = new \Zend\Mime\Message();
     $emailBody->setParts($emailMimeParts);
     $zmail->setBody($emailBody);
     $zmail->getHeaders()->removeHeader('to');
     $zmail->getHeaders()->removeHeader('cc');
     $zmail->getHeaders()->removeHeader('bcc');
     $zmail->addTo($target['email']);
     return $zmail;
 }
コード例 #24
0
 public function mensajecomentarioAction()
 {
     $va_email = $this->params()->fromRoute('va_email', 0);
     $va_nombre_cliente = $this->params()->fromRoute('va_nombre_cliente', 0);
     $bodyHtml = '<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml">
                                            <head>
                                            <meta http-equiv="Content-type" content="text/html;charset=UTF-8"/>
                                            </head>
                                            <body>
                                                 <div style="color: #7D7D7D"><br />
                                                  Hola <strong style="color:#133088; font-weight: bold;">' . utf8_decode($va_nombre_cliente) . '</strong><br />
                                                  <br />Tu  comentario ha sido eliminado por ser inapropiado<br/><br/>
                                                  <br /><br /><hr /><br />Cordialmente,<br /><span style="color:#000; font-size: 18px; margin-top:8px;">El Equipo de listadelsabor.com</span><br /><br />
                                                  </div>
                                            </body>
                                            </html>';
     $message = new Message();
     $message->addTo($va_email, $va_nombre_cliente)->setFrom('*****@*****.**', 'listadelsabor.com')->setSubject('Moderación de comentario de ListaDelSabor.com');
     $bodyPart = new \Zend\Mime\Message();
     $bodyMessage = new \Zend\Mime\Part($bodyHtml);
     $bodyMessage->type = 'text/html';
     $bodyPart->setParts(array($bodyMessage));
     $message->setBody($bodyPart);
     $message->setEncoding('UTF-8');
     $transport = $this->getServiceLocator()->get('mail.transport');
     $transport->send($message);
     $this->redirect()->toUrl('/usuario/comentarios/index');
 }
コード例 #25
0
ファイル: SignController.php プロジェクト: hamichen/CMS
 public function lostPasswordAction()
 {
     $viewModel = new ViewModel();
     $form = new LostPasswordForm();
     $accountFilter = new AccountFIlter();
     $filter = new InputFilter();
     $filter->add($accountFilter->get('email'));
     $form->setInputFilter($filter);
     $request = $this->getRequest();
     if ($request->isPost()) {
         $data = $request->getPost();
         $form->setData($data);
         if ($form->isValid()) {
             $em = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default');
             // 找到使用者
             if ($user = $em->getRepository('Base\\Entity\\User')->findOneBy(array('email' => $form->get('email')->getValue()))) {
                 $md5 = md5(time() . $user->getUserName() . $user->getEmail());
                 $user->setCheckCode($md5);
                 $em->persist($user);
                 $em->flush();
                 $view = new \Zend\View\Renderer\PhpRenderer();
                 $resolver = new \Zend\View\Resolver\TemplateMapResolver();
                 $resolver->setMap(array('mailLayout' => __DIR__ . '/../../../../Application/view/layout/layout-mail.phtml', 'mailTemplate' => __DIR__ . '/../../../view/user/sign/lost-password-mail.phtml'));
                 $view->setResolver($resolver);
                 $uri = $this->getRequest()->getUri();
                 $scheme = $uri->getScheme();
                 $host = $uri->getHost();
                 $base = sprintf('%s://%s%s', $scheme, $host, $this->getRequest()->getBasePath());
                 $viewModel->setTemplate('mailTemplate')->setVariables(array('user' => $user, 'url' => $base));
                 $content = $view->render($viewModel);
                 $viewLayout = new ViewModel();
                 $viewLayout->setTemplate('mailLayout')->setVariables(array('content' => $content));
                 $body = $view->render($viewLayout);
                 $bodyPart = new \Zend\Mime\Message();
                 $bodyMessage = new \Zend\Mime\Part($body);
                 $bodyMessage->type = 'text/html';
                 $bodyPart->setParts(array($bodyMessage));
                 $message = new Mail\Message();
                 $message->addTo($user->getEmail(), $user->getusername());
                 $message->setFrom('*****@*****.**', '系統通知信');
                 $message->setSubject('重設密碼通知信');
                 $message->setBody($bodyPart);
                 $message->setEncoding('UTF-8');
                 $transport = new Mail\Transport\Sendmail();
                 $transport->send($message);
                 // $viewModel->setTemplate('user/login/send-mail.phtml');
                 $this->flashmessenger()->addMessage($user->getEmail());
                 return $this->redirect()->toRoute('user/default', array('controller' => 'sign', 'action' => 'send-mail'));
                 // return $viewModel;
             } else {
                 $this->flashmessenger()->addMessage('您輸入了錯誤的帳號或電子郵件');
             }
         }
     }
     $viewModel->setVariable('form', $form);
     $viewModel->setVariable('flashMessages', $this->flashMessenger()->getMessages());
     return $viewModel;
 }
コード例 #26
0
 /**
  * Create a email based on it's theme an params
  *
  * @param string $address
  * @param string $name
  * @throws Exception
  * @return \Zend\Mail\Message
  */
 protected function _constructEmail($address, $name)
 {
     $content = $this->_template->render();
     if ('' == $this->_replyTo) {
         $this->_replyTo = $this->_template->getTestament()->getReplyTo();
     }
     if ('' == $this->_fromName) {
         $this->_fromName = $this->_template->getTestament()->getFromName();
     }
     if ('' == $this->_fromAddress) {
         $this->_fromAddress = $this->_template->getTestament()->getFromAddress();
     }
     if ('' == $this->_subject) {
         $this->_subject = $this->_template->getTestament()->getFromAddress();
     }
     $contentParts = array();
     $partText = new Part($content->getText());
     $partText->encoding = Mime::ENCODING_QUOTEDPRINTABLE;
     $partText->type = Mime::TYPE_TEXT;
     $contentParts[] = $partText;
     $partHtml = new Part($content->getHtml());
     $partHtml->encoding = Mime::ENCODING_QUOTEDPRINTABLE;
     $partHtml->type = Mime::TYPE_HTML;
     $partHtml->charset = 'UTF-8';
     $contentParts[] = $partHtml;
     $alternatives = new \Zend\Mime\Message();
     $alternatives->setParts($contentParts);
     $alternativesPart = new Part($alternatives->generateMessage());
     $alternativesPart->type = "multipart/alternative; boundary=\"" . $alternatives->getMime()->boundary() . "\"";
     $body = new \Zend\Mime\Message();
     $body->addPart($alternativesPart);
     foreach ($this->_attachments as $attachmentSrc) {
         $attachment = new Part(fopen($attachmentSrc['filelocation'], 'r'));
         $attachment->filename = $attachmentSrc['filename'];
         $attachment->encoding = Mime::ENCODING_BASE64;
         $attachment->type = Mime::DISPOSITION_ATTACHMENT;
         $attachment->disposition = true;
         $body->addPart($attachment);
     }
     $subject = $this->_subject;
     foreach ($this->_variables as $name => $variable) {
         $subject = str_replace('{{:' . $name . ':}}', $variable, $subject);
     }
     $message = new Message();
     $message->setSubject($subject);
     $message->setFrom($this->_fromAddress, $this->_fromName);
     if ($this->_replyTo) {
         $message->setReplyTo($this->_replyTo);
     }
     $message->setBody($body);
     $message->setTo($address, $name);
     $message->setEncoding("UTF-8");
     return $message;
 }
コード例 #27
0
ファイル: UserController.php プロジェクト: projectHN/mentor
 public function sendemailAction()
 {
     $data = $this->params()->fromQuery();
     if (!isset($data['email']) || !$data['email']) {
         return 'Dữ liệu không đúng';
     }
     if (!isset($data['activeKey']) || !$data['activeKey']) {
         return 'Dữ liệu không đúng';
     }
     $validator = new \Zend\Validator\EmailAddress();
     if ($validator->isValid($data['email'])) {
         $user = new User();
         $user->setEmail($data['email']);
         $user->setActiveKey($data['activeKey']);
         /* @var $userMapper \User\Model\UserMapper */
         $userMapper = $this->getServiceLocator()->get('User\\Model\\UserMapper');
         if ($userMapper->checkExistsUserActive($user)) {
             $renderer = $this->getServiceLocator()->get('Zend\\View\\Renderer\\RendererInterface');
             // Email content
             $viewContent = new \Zend\View\Model\ViewModel(array('activeLink' => Uri::buildAutoHttp('/user/user/activeaccount', ['u' => $user->getEmail(), 'c' => $user->getActiveKey()])));
             $viewContent->setTemplate('email/activeFill');
             // set in module.config.php
             $content = $renderer->render($viewContent);
             // Email layout
             $viewLayout = new \Zend\View\Model\ViewModel(array('content' => $content));
             $viewLayout->setTemplate('email/layout');
             // set in module.config.php
             $message = new Message();
             $message->addTo($data['email']);
             $message->addFrom('*****@*****.**', $_SERVER['HTTP_HOST']);
             $message->setSubject('Welcome to ' . $_SERVER['HTTP_HOST']);
             $html = new \Zend\Mime\Part($renderer->render($viewLayout));
             $html->type = 'text/html';
             $body = new \Zend\Mime\Message();
             $body->setParts(array($html));
             $message->setBody($body);
             $message->setEncoding("UTF-8");
             $smtp = new \Zend\Mail\Transport\Smtp();
             $config = $this->getServiceLocator()->get('Config');
             $options = new SmtpOptions($config['smtpOptions']);
             $smtp->setOptions($options);
             $smtp->send($message);
             $json = new JsonModel();
             return $json->setVariable('Status', 'Đã xong');
         } else {
             return 'Dữ liệu không phù hợp';
         }
     }
 }
コード例 #28
0
 public function contactenosAction()
 {
     $view = new ViewModel();
     $comidas = $this->joinAction()->toArray();
     $storage = new \Zend\Authentication\Storage\Session('Auth');
     $session = $storage->read();
     if (!isset($session)) {
         $face = new \Usuario\Controller\ClientesController();
         $facebook = $face->facebook();
         $this->layout()->loginUrl = $facebook['loginUrl'];
         $this->layout()->user = $facebook['user'];
         if ($facebook['id_facebook']) {
             $url = '/contactenos';
             $id_face = $this->getClientesTable()->usuarioface($facebook['email']);
             if (count($id_face) > 0) {
                 if ($id_face[0]['id_facebook'] == '') {
                     $this->getClientesTable()->idfacebook($id_face[0]['in_id'], $facebook['id_facebook'], $facebook['logoutUrl']);
                     AuthController::sessionfacebook($facebook['email'], $facebook['id_facebook'], $url);
                 } else {
                     $this->getClientesTable()->idfacebook2($id_face[0]['in_id'], $facebook['logoutUrl']);
                     AuthController::sessionfacebook($facebook['email'], $facebook['id_facebook'], $url);
                 }
             } else {
                 $this->getClientesTable()->insertarusuariofacebbok($facebook['name'], $facebook['email'], $facebook['id_facebook'], $facebook['logoutUrl']);
                 AuthController::sessionfacebook($facebook['email'], $facebook['id_facebook'], $url);
             }
         }
     }
     $this->layout()->comidas = $comidas;
     $this->layout()->clase = 'Solicita';
     $form = new Contactenos("form");
     $request = $this->getRequest();
     if ($request->isPost()) {
         $datos = array();
         $datos['nombre'] = htmlspecialchars($this->params()->fromPost('nombre', 0));
         $datos['email'] = htmlspecialchars($this->params()->fromPost('email', 0));
         $datos['asunto'] = htmlspecialchars($this->params()->fromPost('asunto', 0));
         $datos['mensaje'] = htmlspecialchars($this->params()->fromPost('mensaje', 0));
         // $form->setInputFilter(new \Application\Form\ContactenosFiltro());
         $form->setData($datos);
         if ($form->isValid()) {
             $bodyHtml = '<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml">
                                            <head>
                                            <meta http-equiv="Content-type" content="text/html;charset=UTF-8"/>
                                            </head>
                                            <body>
                                                 <div style="color: #7D7D7D"><br />
                                                  Nombre <strong style="color:#133088; font-weight: bold;">' . utf8_decode($datos['nombre']) . '</strong><br />
                                                  Email <strong style="color:#133088; font-weight: bold;">' . utf8_decode($datos['email']) . '</strong><br />
                                                  Asunto <strong style="color:#133088; font-weight: bold;">' . utf8_decode($datos['asunto']) . '</strong><br />
                                                  Mensaje <strong style="color:#133088; font-weight: bold;">' . utf8_decode($datos['mensaje']) . '</strong><br />
                                           
                                                  </div>
                                            </body>
                                            </html>';
             $message = new Message();
             $config = $this->getServiceLocator()->get('Config');
             $message->addTo($config['mail']['transport']['options']['connection_config']['username'], $datos['nombre'])->setFrom($config['mail']['transport']['options']['connection_config']['username'], 'listadelsabor.com')->setSubject('Contactos de ListaDelSabor.com');
             // ->setBody($bodyHtml);
             $bodyPart = new \Zend\Mime\Message();
             $bodyMessage = new \Zend\Mime\Part($bodyHtml);
             $bodyMessage->type = 'text/html';
             $bodyPart->setParts(array($bodyMessage));
             $message->setBody($bodyPart);
             $message->setEncoding('UTF-8');
             $transport = $this->getServiceLocator()->get('mail.transport');
             // new SendmailTransport();
             $transport->send($message);
             $this->flashMessenger()->addMessage('Su mensaje ha sido enviado...');
             $this->redirect()->toUrl($this->getRequest()->getBaseUrl() . '/contactenos');
             // $this->redirect()->toUrl('/contactenos');///application/index
         }
     }
     $flashMessenger = $this->flashMessenger();
     if ($flashMessenger->hasMessages()) {
         $mensajes = $flashMessenger->getMessages();
     }
     $view->setVariables(array('form' => $form, 'mensaje' => $mensajes));
     return $view;
 }
コード例 #29
0
ファイル: NMB2BService.php プロジェクト: BrunoSpy/epeires2
 public function sendErrorEmail($textError)
 {
     $objectManager = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager');
     //TODO récupérer proprement l'organisation concernée
     $org = $objectManager->getRepository('Application\\Entity\\Organisation')->findAll();
     $ipoEmail = $org[0]->getIpoEmail();
     // prepare body with file attachment
     $text = new \Zend\Mime\Part($textError);
     $text->type = \Zend\Mime\Mime::TYPE_TEXT;
     $text->charset = 'utf-8';
     $mimeMessage = new \Zend\Mime\Message();
     $mimeMessage->setParts(array($text));
     $config = $this->getServiceLocator()->get('config');
     $message = new \Zend\Mail\Message();
     $message->addTo($ipoEmail)->addFrom($config['emailfrom'])->setSubject("Erreur lors de l'import de l'AUP via NM B2B")->setBody($mimeMessage);
     $transport = new \Zend\Mail\Transport\Smtp();
     $transportOptions = new \Zend\Mail\Transport\SmtpOptions($config['smtp']);
     $transport->setOptions($transportOptions);
     $transport->send($message);
 }
コード例 #30
0
 /**
  * Send an event by email to the corresponding IPO
  */
 public function sendEventAction()
 {
     $id = $this->params()->fromQuery('id', 0);
     $messages = array();
     if ($id) {
         $objectManager = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager');
         $eventservice = $this->getServiceLocator()->get('EventService');
         $customfieldservice = $this->getServiceLocator()->get('CustomFieldService');
         $event = $objectManager->getRepository('Application\\Entity\\Event')->find($id);
         $formatter = \IntlDateFormatter::create(\Locale::getDefault(), \IntlDateFormatter::FULL, \IntlDateFormatter::FULL, 'UTC', \IntlDateFormatter::GREGORIAN, 'dd LLL, HH:mm');
         if ($event) {
             $content = 'Nom : ' . $eventservice->getName($event) . '<br />';
             $content .= 'Début : ' . $formatter->format($event->getStartdate()) . '<br />';
             $content .= 'Fin : ' . ($event->getEnddate() ? $formatter->format($event->getEnddate()) : 'Inconnu') . '<br />';
             foreach ($event->getCustomFieldsValues() as $value) {
                 $content .= $value->getCustomField()->getName() . ' : ' . $customfieldservice->getFormattedValue($value->getCustomField(), $value->getValue()) . '<br />';
             }
             $text = new \Zend\Mime\Part($content);
             $text->type = \Zend\Mime\Mime::TYPE_HTML;
             $text->charset = 'utf-8';
             $mimeMessage = new \Zend\Mime\Message();
             $mimeMessage->setParts(array($text));
             $config = $this->serviceLocator->get('config');
             if (!$config['emailfrom'] || !$config['smtp']) {
                 $messages['error'][] = "Envoi d'email non configuré, contactez votre administrateur.";
             } else {
                 $message = new \Zend\Mail\Message();
                 $message->addTo($event->getOrganisation()->getIpoEmail())->addFrom($config['emailfrom'])->setSubject("Envoi d'un évènement par le CDS : " . $eventservice->getName($event))->setBody($mimeMessage);
                 $transport = new \Zend\Mail\Transport\Smtp();
                 $transportOptions = new \Zend\Mail\Transport\SmtpOptions($config['smtp']);
                 $transport->setOptions($transportOptions);
                 try {
                     $transport->send($message);
                     $messages['success'][] = "Evènement correctement envoyé à " . $event->getOrganisation()->getIpoEmail();
                 } catch (\Exception $e) {
                     $messages['error'][] = $e->getMessage();
                 }
             }
         } else {
             $messages['error'][] = "Envoi d'email impossible : évènement non trouvé.";
         }
     } else {
         $messages['error'][] = "Envoi d'email impossible : évènement non trouvé.";
     }
     $json = array();
     $json['messages'] = $messages;
     return new JsonModel($json);
 }