Example #1
0
 /**
  * Send contact mail
  * @param $controller
  * @param $data
  */
 public static function sendContactMail($controller, $data)
 {
     // prepare html content
     $comments = nl2br($data['comments']);
     // line break
     $content = '';
     $content .= '<table>';
     $content .= '<tbody>';
     $content .= "<tr><td>First Name:</td><td>{$data['firstName']}</td></tr>";
     $content .= "<tr><td>Last Name:</td><td>{$data['lastName']}</td></tr>";
     $content .= "<tr><td>Phone Number:</td><td>{$data['phone']}</td></tr>";
     $content .= "<tr><td>Email:</td><td>{$data['email']}</td></tr>";
     $content .= "<tr><td>Company:</td><td>{$data['company']}</td></tr>";
     $content .= "<tr><td>Job Title:</td><td>{$data['jobTitle']}</td></tr>";
     $content .= "<tr><td>Comments:</td><td>{$comments}</td></tr>";
     $content .= '</tbody>';
     $content .= '</table>';
     $html = new MimePart($content);
     $html->type = "text/html";
     $body = new MimeMessage();
     $body->setParts(array($html));
     $message = new Message();
     $message->setBody($body);
     // subject
     $subject = 'Contact from Papertask';
     $message->setSubject($subject);
     // get transport
     $transport = $controller->getServiceLocator()->get('mail.transport');
     $message->addTo($transport->mailOptions['contact']);
     $message->addFrom($transport->mailOptions['contact']);
     $transport->send($message);
 }
Example #2
0
 /**
  * @param string $queue_name
  * @param \Zend\Mail\Message $mail
  */
 public function add($queue_name, \Zend\Mail\Message $message)
 {
     if (!count($message->getFrom())) {
         $message->addFrom($this->config['default_from']);
     }
     $this->table->add($queue_name, $message);
 }
Example #3
0
 /**
  * @param string $subject
  * @param string $message
  * @param null|string|array $to
  * @param null|string|array $cc
  * @param null|string|array $bcc
  * @return array
  */
 public function sendMail($subject, $message, $to = null, $cc = null, $bcc = null)
 {
     $return = array('success' => true, 'msg' => null);
     $partBody = new MimePart($this->getPartHeader() . $message . $this->getPartFooter());
     $partBody->type = Mime::TYPE_HTML;
     $partBody->charset = 'utf-8';
     $this->body->setParts(array($partBody));
     $subject = '[' . APPLICATION_NAME . '] ' . $subject;
     $mail = new Message();
     $mail->addFrom(self::FROM);
     $mail->setSubject($subject);
     $mail->setBody($this->body);
     $mail->setTo($to);
     if ($cc) {
         $mail->setCc($cc);
     }
     if ($bcc) {
         $mail->setBcc($bcc);
     }
     try {
         $this->transport->send($mail);
     } catch (\Exception $e) {
         $return['success'] = false;
         $return['msg'] = _('mail.message.not_sent');
         //throw new \Exception($e->getMessage(), $e->getCode());
     }
     return $return;
 }
Example #4
0
 public function run()
 {
     $transport = new SmtpTransport(new SmtpOptions(array('name' => $this->host, 'host' => $this->host, 'port' => $this->port, 'connection_config' => array('username' => $this->sender->getUsername(), 'password' => $this->sender->getPassword()))));
     if ($this->auth !== null) {
         $transport->getOptions()->setConnectionClass($this->auth);
     }
     $message = new Message();
     $message->addFrom($this->sender->getUsername())->setSubject($this->subject);
     if ($this->bcc) {
         $message->addBcc($this->recipients);
     } else {
         $message->addTo($this->recipients);
     }
     $body = new MimeMessage();
     if ($this->htmlBody == null) {
         $text = new MimePart($this->textBody);
         $text->type = "text/plain";
         $body->setParts(array($text));
     } else {
         $html = new MimePart($this->htmlBody);
         $html->type = "text/html";
         $body->setParts(array($html));
     }
     $message->setBody($body);
     $transport->send($message);
 }
Example #5
0
 public function sendMail(MailMessage $message)
 {
     $from = $message->getFrom();
     if (count($from) == 0) {
         $message->addFrom($this->createSenderAddress());
     }
     $this->transport->send($message);
 }
Example #6
0
 /**
  * @param string $to
  * @param Template $template
  * @param array $data
  * @return Message
  */
 public function assemble($to, Template $template, array $data)
 {
     $html = new MimePart($template->getBody($data));
     $html->type = "text/html";
     $body = new MimeMessage();
     $body->addPart($html);
     $message = new Message();
     $message->addFrom($this->config['from-email'], $this->config['from-name'])->addTo($to)->setSubject($template->getSubject())->setBody($body)->setEncoding("UTF-8");
     return $message;
 }
Example #7
0
 public function testRestoreFromSerializedString()
 {
     $this->message->addTo('*****@*****.**', 'ZF DevTeam');
     $this->message->addFrom('*****@*****.**', "Matthew Weier O'Phinney");
     $this->message->addCc('*****@*****.**', 'ZF Contributors List');
     $this->message->setSubject('This is a subject');
     $this->message->setBody('foo');
     $serialized = $this->message->toString();
     $restoredMessage = Message::fromString($serialized);
     $this->assertEquals($serialized, $restoredMessage->toString());
 }
Example #8
0
 private function createMessage()
 {
     $message = new Message();
     $config = $this->config['message'];
     $message->addTo($config['to']);
     if ($config['from']) {
         $message->addFrom($config['from']);
     }
     $message->setSender($config['sender']['address'], $config['sender']['name']);
     return $message;
 }
Example #9
0
 /**
  * Send password lost email.
  *
  * @param NewUserModel $activation
  * @param MemberModel $member
  */
 public function sendPasswordLostMail(NewUserModel $newUser, MemberModel $member)
 {
     $body = $this->render('user/email/reset', ['user' => $newUser, 'member' => $member]);
     $translator = $this->getServiceManager()->get('translator');
     $message = new Message();
     $config = $this->getConfig();
     $message->addFrom($config['from']);
     $message->addTo($newUser->getEmail());
     $message->setSubject($translator->translate('Password reset code for the GEWIS Website'));
     $message->setBody($body);
     $this->getTransport()->send($message);
 }
Example #10
0
 /**
  * Send registration email.
  *
  * @param NewUserModel $newUser
  * @param MemberModel $member
  */
 public function sendRegisterEmail(NewUserModel $newUser, MemberModel $member)
 {
     $body = $this->render('user/email/register', array('user' => $newUser, 'member' => $member));
     $translator = $this->getServiceManager()->get('translator');
     $message = new Message();
     $config = $this->getConfig();
     $message->addFrom($config['from']);
     $message->addTo($newUser->getEmail());
     $message->setSubject($translator->translate('Account activation code for the GEWIS Website'));
     $message->setBody($body);
     $this->getTransport()->send($message);
 }
Example #11
0
 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);
 }
Example #12
0
 protected function prepareMail(MailMessage $mail, array $viewVariables, $mailTemplateName)
 {
     $mailBodyOutput = $this->getRenderContent($viewVariables, $mailTemplateName);
     $mailBodyOutput = htmlspecialchars_decode(htmlentities($mailBodyOutput, ENT_NOQUOTES, 'UTF-8', false), ENT_NOQUOTES);
     $content = new MimeMessage();
     $part = new Part($mailBodyOutput);
     $part->type = 'text/html';
     $content->addPart($part);
     $mail->addFrom($this->mailAddress, $this->senderName);
     $this->addMailTargets($mail);
     $mail->setEncoding('UTF-8');
     $mail->setBody($content);
 }
Example #13
0
 public function send()
 {
     $smtpOptions = new SmtpOptions(array('name' => 'smtp.gmail.com', 'host' => 'smtp.gmail.com', 'connection_class' => 'login', 'connection_config' => array('username' => '*****@*****.**', 'password' => 'optimus@123', 'port' => 465, 'ssl' => 'TLS')));
     $html = new MimePart($this->getBody());
     $html->type = "text/html";
     $body = new MimeMessage();
     $body->setParts(array($html));
     $mailTransport = new Smtp();
     $mailTransport->setOptions($smtpOptions);
     $mail = new Message();
     $mail->addFrom('*****@*****.**', 'Travelopod')->setEncoding('utf-8')->setTo($this->getTo())->setSubject($this->getSubject())->setBody($body);
     $send = $mailTransport->send($mail);
     $mailTransport->disconnect();
 }
 public function contruirCorreo(array $param = null)
 {
     $mail = new Mail\Message();
     $mail->setTo('*****@*****.**', 'Jeisson');
     //de
     $mail->addFrom('*****@*****.**');
     //para
     $mail->setSubject('Clave ingreso');
     //asunto
     $cfg = array('ssl' => 'tls', 'username' => '*****@*****.**', 'password' => 'JeissonB_1989');
     $smtpOption = new Mail\Transport\SmtpOptions();
     $smtpOption->setHost('smtp.gmail.com')->setConnectionClass('login')->setName('smtp.gmail.com')->setConnectionConfig($cfg);
     $smtp = new Mail\Transport\Smtp($smtpOption);
     $smtp->send($mail);
 }
Example #15
0
 /**
  * Send activity creation email.
  *
  * @param ActivityModel $activity
  */
 public function sendActivityCreationEmail(ActivityModel $activity)
 {
     $body = $this->render('email/activity', ['activity' => $activity]);
     $html = new MimePart($body);
     $html->type = "text/html";
     $mimeMessage = new MimeMessage();
     $mimeMessage->setParts([$html]);
     $message = new Message();
     $config = $this->getConfig();
     $message->addFrom($config['from']);
     $message->addTo($config['to']['activity_creation']);
     $message->setSubject('Nieuwe activiteit aangemaakt op de GEWIS website | New activity was created on the GEWIS website');
     $message->setBody($mimeMessage);
     $this->getTransport()->send($message);
 }
Example #16
0
 /**
  * Send options overdue email.
  *
  * @param array $options
  */
 public function sendOptionsOverdueEmail($options)
 {
     $body = $this->render('email/options-overdue', ['options' => $options]);
     $html = new MimePart($body);
     $html->type = "text/html";
     $mimeMessage = new MimeMessage();
     $mimeMessage->setParts([$html]);
     $message = new Message();
     $config = $this->getConfig();
     $message->addFrom($config['from']);
     $message->addTo($config['to']['activity_calendar']);
     $message->setSubject('Activiteiten kalender opties verlopen | Activity calendar options expired');
     $message->setBody($mimeMessage);
     $this->getTransport()->send($message);
 }
 public function run()
 {
     $config = Config::get('xmailer.imap');
     $mail = new StorageImap(array('host' => $config['host'], 'user' => $config['user'], 'password' => $config['password']));
     //$mail = new StorageImap(Config::get('xmailer.imap'));
     if ($mail->countMessages() > 0) {
         $message = $mail->getMessage(1);
         if ($message->getHeaders()->get("from") != null) {
             $from = $message->getHeaders()->get("from")->toString();
         } else {
             $from = "";
         }
         if ($message->getHeaders()->get("to") != null) {
             $to = $message->getHeaders()->get("to")->toString();
         } else {
             $to = "";
         }
         preg_match("/[\\w._%+-]+@[\\w.-]+.[\\w]{2,}/", $from, $fromEmails);
         preg_match("/[\\w._%+-]+@[\\w.-]+.[\\w]{2,}/", $to, $toEmails);
         $sendTo = $this->getEmailAdresses($toEmails);
         if ($this->isValidSender($fromEmails[0])) {
             foreach ($sendTo as $mailadress) {
                 $fwd = new Message();
                 $fwd->setBody($message->getContent());
                 $h = $message->getHeaders();
                 $h->removeHeader('From');
                 $h->removeHeader('To');
                 $h->removeHeader('Reply-To');
                 $fwd->setHeaders($h);
                 $fwd->addFrom($mailadress['from']);
                 $fwd->addTo($mailadress['to']);
                 if (Config::get('xmailer.replyto')) {
                     $fwd->addReplyTo($fromEmails[0]);
                 }
                 $transport = new SendmailTransport();
                 $transport->send($fwd);
             }
             $mail->moveMessage(1, "INBOX.Sent");
         } else {
             $mail->moveMessage(1, "INBOX.Spam");
         }
         return t("%d email sent to %d People.", 1, count($sendTo));
     }
     return t("No emails sent.");
 }
Example #18
0
 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);
     }
 }
 public function indexAction()
 {
     // Setup SMTP transport
     $transport = new SmtpTransport();
     $form = new AuthMDPForm();
     $id = $this->params()->fromRoute('id');
     // Récupération id pour messages erreurs
     $request = $this->getRequest();
     $envoyer = $request->getPost('confirm');
     if ($envoyer == 'Envoyer') {
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $data = $form->getData();
             $userController = $this->getServiceLocator()->get('UserController');
             $usermail = $userController->getUserTable()->getUserMail($data['login']);
             $mail = $usermail->Email;
             $login = $usermail->Login;
             if (isset($mail)) {
                 $_SESSION['user']['mail'] = $mail;
                 $newmdp = $userController->RandomPass();
                 // Génération nouveau mdp
                 $changePass = $userController->getUserTable()->ChangePassUser($usermail->id, $newmdp);
                 // Enregistrement newMDP
                 $corps = "Bonjour," . PHP_EOL;
                 $corps .= "Votre mot de passe a bien été changé, voici vos nouveaux identifiants :" . PHP_EOL;
                 $corps .= "Nom Utilisateur : " . $login . PHP_EOL;
                 $corps .= "Mot de passe : " . $newmdp . PHP_EOL;
                 $corps .= "Si vous n'avez pas demandé à changer de mot de passe, merci de contacter le support." . PHP_EOL;
                 $corps .= "Cordialement," . PHP_EOL;
                 $corps .= "L'équipe WEBAXYS";
                 // MESSAGE + ENVOI
                 $message = new Message();
                 $message->addFrom('*****@*****.**')->addTo($mail)->setSubject('IWG : Changement de mot de passe')->setBody($corps)->setEncoding("UTF-8");
                 $transport->send($message);
                 return $this->redirect()->toRoute('Auth', array('id' => 2));
             } else {
                 return $this->redirect()->toRoute('AuthMDP', array('id' => 1));
             }
         }
     } elseif ($envoyer == 'Annuler') {
         return $this->redirect()->toRoute('Auth');
     }
     return array('form' => $form, 'id' => $id);
 }
 private function sendEmail($destino, $subject, $body)
 {
     try {
         $trans = new SmtpTransport();
         $msg = new Message();
         $qb = $this->getEntityManager()->getRepository("Application\\Entity\\Email")->createQueryBuilder('e');
         $emails = $qb->select()->getQuery()->getResult();
         $email = $emails[0];
         $options = new SmtpOptions(array('name' => $email->getEmailSmtp(), 'host' => $email->getEmailSmtp(), 'port' => 587, 'connection_class' => 'login', 'connection_config' => array('username' => $email->getEmailUsername(), 'password' => $email->getEmailPassword(), 'ssl' => 'tls')));
         $msg->addFrom($email->getEmailUsername())->addTo($destino)->setsubject($subject);
         $msg->setBody($body);
         $msg->setEncoding("UTF-8");
         $trans->setOptions($options);
         $trans->send($msg);
     } catch (Exception $e) {
         $this->flashMessenger()->addErrorMessage("Falha ao enviar email");
     }
     return $this->redirect()->toRoute("questions-list");
 }
 /**
  * Immediately send notification
  *
  * @param string $email
  * @param string $title
  * @param string $messageDesc
  * @return boolean|string
  */
 public static function immediatelySendNotification($email, $title, $messageDesc)
 {
     try {
         // fire the send email notification event
         ApplicationEvent::fireSendEmailNotificationEvent($email, $title);
         // add the mime type
         $message = new MimePart($messageDesc);
         $message->type = 'text/html';
         $body = new MimeMessage();
         $body->setParts([$message]);
         $messageInstance = new Message();
         $messageInstance->addFrom(ApplicationSettingService::getSetting('application_notification_from'))->addTo($email)->setSubject($title)->setBody($body)->setEncoding('UTF-8');
         self::getMessageTransport()->send($messageInstance);
     } catch (Exception $e) {
         ApplicationErrorLogger::log($e);
         return 'Error: ' . $e->getMessage() . "\n";
     }
     return true;
 }
 public function indexAction()
 {
     $config = $this->getServiceLocator()->get('Config');
     // Setup SMTP transport using LOGIN authentication
     $transport = new SmtpTransport();
     $options = new SmtpOptions(array('name' => 'gmail', "host" => "smtp.gmail.com", "port" => 587, "connection_class" => "plain", "connection_config" => array("username" => "*****@*****.**", "password" => "noeliabelen", "ssl" => "tls")));
     $transport->setOptions($options);
     $message = new Message();
     $message->addFrom("*****@*****.**", "Tineo")->addTo("*****@*****.**")->setSubject("Sending an email from Zend\\Mail!");
     $message->setBody("This is the message body.");
     $message->setEncoding("UTF-8");
     $transport = new SmtpTransport();
     $transport->setOptions($options);
     // $transport->send($message);
     // $translator = $this->getServiceLocator ()->get ( 'translator' );
     // $translator->setLocale ( "en_US" );
     // $config['translator']['locale'] = "En_US" ;
     // var_dump($config['translator']['locale']);
     return new ViewModel();
 }
 public function createService(ServiceLocatorInterface $services)
 {
     $config = $services->get('config');
     if ($config instanceof Traversable) {
         $config = ArrayUtils::iteratorToArray($config);
     }
     $config = $config['phly_contact']['message'];
     $message = new Message();
     if (isset($config['to'])) {
         $message->addTo($config['to']);
     }
     if (isset($config['from'])) {
         $message->addFrom($config['from']);
     }
     if (isset($config['sender']) && isset($config['sender']['address'])) {
         $address = $config['sender']['address'];
         $name = isset($config['sender']['name']) ? $config['sender']['name'] : null;
         $message->setSender($address, $name);
     }
     return $message;
 }
    /**
     * Composes & sends the email from a contact message
     * @param Contact $contactMessage
     * @return mixed
     */
    public function sendMessage(Contact $contactMessage)
    {
        $serverName = $_SERVER['HTTP_HOST'] ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME'];
        // PREPARE THE EMAIL MESSAGE
        $message = new Message();
        $message->addFrom(new Address($contactMessage->getEmail(), $contactMessage->getFirstName() . ' ' . $contactMessage->getLastName()));
        $message->setSubject($contactMessage->getSubject());
        $body = <<<MSG
New Message 

From: {$contactMessage->getFirstName()} {$contactMessage->getLastName()} 

Subject: [{$serverName} contact] {$contactMessage->getSubject()} 

Message: {$contactMessage->getMessage()} 

MSG;
        $message->setBody($body);
        // SEND THE EMAIL
        return $this->getServiceLocator()->get('transport')->send($message);
    }
Example #25
0
 public function sendMail($mail)
 {
     // Build the message body
     $mimeParts = array();
     foreach ($mail->getParts() as $part) {
         $mimePart = new MimePart($part->getContent());
         $mimePart->type = $part->getType();
         $mimeParts[] = $mimePart;
     }
     $body = new MimeMessage();
     $body->setParts($mimeParts);
     // Build the message.
     $message = new Mail\Message();
     $message->setBody($body);
     // Set the participants
     foreach ($mail->getParticipants() as $participant) {
         if ($participant->getComposition() == 'to') {
             $message->addTo($participant->getAddress(), $participant->getName());
         }
         if ($participant->getComposition() == 'cc') {
             $message->addCc($participant->getAddress(), $participant->getName());
         }
         if ($participant->getComposition() == 'bcc') {
             $message->addBcc($participant->getAddress(), $participant->getName());
         }
         if ($participant->getComposition() == 'from') {
             $message->addFrom($participant->getAddress(), $participant->getName());
         }
     }
     // Set the subject
     $message->setSubject($mail->getSubject());
     $contentType = $mail->getContentType();
     if ($contentType) {
         $message->getHeaders()->get('content-type')->setType($contentType);
     }
     // Create the transport and send.
     $transport = new SmtpTransport();
     $transport->setOptions(new SmtpOptions($this->options));
     $transport->send($message);
 }
Example #26
0
 public function send($email, $subject, $content, $url = null)
 {
     $view = new ViewModel();
     $view->setTemplate('email/common');
     $view->setVariables(array('title' => $subject, 'content' => $content, 'url' => $url));
     $viewRender = $this->getServiceLocator()->get('ViewRenderer');
     $htmlBody = $viewRender->render($view);
     $htmlPart = new MimePart($htmlBody);
     $htmlPart->type = Mime::TYPE_HTML;
     $body = new MimeMessage();
     $body->setParts(array($htmlPart));
     $message = new Message();
     $message->setEncoding("UTF-8");
     $fromEmail = $this->config['transport']['options']['connection_config']['username'];
     $message->addFrom($fromEmail, "e财会")->addTo($email)->setSubject($subject);
     $message->setBody($body);
     // Set UTF-8 charset
     $headers = $message->getHeaders();
     $headers->removeHeader('Content-Type');
     $headers->addHeaderLine('Content-Type', 'text/html; charset=UTF-8');
     $this->smtp->send($message);
 }
Example #27
0
 public function __invoke($comment)
 {
     $serviceManager = $this->getServiceLocator()->getServiceLocator();
     $viewHelperManager = $serviceManager->get('viewhelpermanager');
     $serverUrlHelper = $viewHelperManager->get('serverUrl');
     $mailerService = $serviceManager->get('RbComment\\Mailer');
     $config = $serviceManager->get('Config');
     $mailerConfig = $config['rb_comment']['email'];
     $htmlContent = $comment->content;
     $htmlContent .= '<br><br>';
     $htmlContent .= '<a href="' . $serverUrlHelper() . $comment->uri . '#rbcomment-' . $comment->id . '">' . $mailerConfig['context_link_text'] . '</a>';
     $html = new MimePart($htmlContent);
     $html->type = "text/html";
     $body = new MimeMessage();
     $body->setParts(array($html));
     $message = new Message();
     $message->addFrom($mailerConfig['from'])->setSubject($mailerConfig['subject'])->setBody($body);
     foreach ($mailerConfig['to'] as $mConfig) {
         $message->addTo($mConfig);
     }
     $mailerService->send($message);
 }
Example #28
0
 /**
  * @param  UserInterface $user
  * @return Message
  */
 protected function getMessage(UserInterface $user)
 {
     // Emailing logic here
     $content = $this->renderMessageContent($user);
     $htmlPart = new MimePart($content);
     $htmlPart->type = "text/html";
     $textPart = new MimePart($content);
     $textPart->type = "text/plain";
     $body = new MimeMessage();
     $body->setParts(array($textPart, $htmlPart));
     $message = new Message();
     $message->addFrom($this->getOptions()->get('from_email'), $this->getOptions()->get('from_name'));
     $message->addTo($user->getEmail(), $user->getFirstName() . ' ' . $user->getLastName());
     $ccs = $this->getOptions()->get('copy_to', array());
     foreach ($ccs as $cc) {
         $message->addCc($cc);
     }
     $message->setSubject($this->getOptions()->get('reset_subject', 'Please Reset Your Password'));
     $message->setEncoding("UTF-8");
     $message->setBody($body);
     $message->getHeaders()->get('content-type')->setType('multipart/alternative');
     return $message;
 }
Example #29
0
 public function testSettingNonAsciiEncodingForcesMimeEncodingOfSomeHeaders()
 {
     $this->message->addTo('*****@*****.**', 'ZF DevTeam');
     $this->message->addFrom('*****@*****.**', "Matthew Weier O'Phinney");
     $this->message->addCc('*****@*****.**', 'ZF Contributors List');
     $this->message->addBcc('*****@*****.**', 'ZF CR Team');
     $this->message->setSubject('This is a subject');
     $this->message->setEncoding('UTF-8');
     $test = $this->message->getHeaders()->toString();
     $expected = '=?UTF-8?Q?ZF=20DevTeam?=';
     $this->assertContains($expected, $test);
     $this->assertContains('<*****@*****.**>', $test);
     $expected = "=?UTF-8?Q?Matthew=20Weier=20O'Phinney?=";
     $this->assertContains($expected, $test, $test);
     $this->assertContains('<*****@*****.**>', $test);
     $expected = '=?UTF-8?Q?ZF=20Contributors=20List?=';
     $this->assertContains($expected, $test);
     $this->assertContains('<*****@*****.**>', $test);
     $expected = '=?UTF-8?Q?ZF=20CR=20Team?=';
     $this->assertContains($expected, $test);
     $this->assertContains('<*****@*****.**>', $test);
     $expected = 'Subject: =?UTF-8?Q?This=20is=20a=20subject?=';
     $this->assertContains($expected, $test);
 }
Example #30
0
 /**
  * send email
  *
  * @param        $fromemail
  * @param        $accessToken
  * @param        $email_type
  * @param        $imap_server
  * @param        $subject
  * @param        $body
  * @param        $toEmail
  * @param        $ccEmail
  * @param        $bccEmail
  * @param        $attachemnts
  * @param string $mailtype
  *
  * @return bool|void
  *
  * @since rt-Helpdesk 0.1
  */
 public function sendemail($fromname, $fromemail, $accessToken, $email_type, $imap_server, $subject, $body, $toEmail, $ccEmail, $bccEmail, $attachemnts, $email = null, $mailtype = 'notification')
 {
     set_time_limit(0);
     if (!$this->try_imap_login($fromemail, $accessToken, $email_type, $imap_server)) {
         return false;
     }
     $transport = new SmtpTransport();
     $smtp_args = array();
     switch ($email_type) {
         case 'goauth':
             $smtp_args['name'] = 'gmail-smtp';
             $smtp_args['host'] = 'smtp.gmail.com';
             $smtp_args['port'] = 465;
             $smtp_args['connection_class'] = 'oauth2';
             $smtp_args['connection_config'] = array('xoauth2_request' => $this->authString, 'ssl' => 'ssl');
             break;
         case 'imap':
             global $rt_imap_server_model;
             $server = $rt_imap_server_model->get_server_by_id($imap_server);
             if (empty($server)) {
                 echo 'Mail Server Not Found. Invalid Server id.';
                 return false;
             }
             $smtp_args['name'] = $server->outgoing_smtp_server;
             $smtp_args['host'] = $server->outgoing_smtp_server;
             $smtp_args['port'] = $server->outgoing_smtp_port;
             $smtp_args['connection_class'] = 'login';
             $smtp_args['connection_config'] = array('username' => $fromemail, 'password' => rtmb_encrypt_decrypt($accessToken), 'ssl' => $server->outgoing_smtp_enc);
             break;
         default:
             break;
     }
     $options = new SmtpOptions($smtp_args);
     $transport->setOptions($options);
     $message = new Message();
     $message->addFrom($fromemail, $fromname);
     if (!empty($email)) {
         $message_id = $reference_id = $in_reply_to = '';
         if ('comment' == $email->refrence_type) {
             $message_id = get_comment_meta($email->refrence_id, '_rtlib_messageid', true);
             $reference_id = get_comment_meta($email->refrence_id, '_rtlib_references', true);
             if (empty($message_id)) {
                 $comment = get_comment($email->refrence_id);
                 $post_id = $comment->comment_post_ID;
             }
         } else {
             if ('post' == $email->refrence_type) {
                 $post_id = $email->refrence_id;
             }
         }
         if (isset($post_id)) {
             $reference_id = get_post_meta($post_id, '_rtlib_references', true);
             $message_id = rtmb_get_reply_to_from_ref_id($reference_id);
             $reply_to = apply_filters('rtlib_reply_to_header', '', $fromemail, $post_id);
             if (!empty($reply_to)) {
                 $message->addCustomeHeader('Reply-To', trim($reply_to));
             }
         }
         //Get reply to header
         if (!empty($message_id)) {
             $message->addCustomeHeader('In-Reply-To', trim($message_id));
         }
         //Get References header
         if (!empty($message_id)) {
             $reference_id = rtmb_add_message_id_in_ref_id($message_id, $reference_id);
         }
         if (!empty($reference_id)) {
             $reference_ids = rtmb_get_reference_id_array($reference_id);
             $_reference_id = implode(' ', $reference_ids);
             $message->addCustomeHeader('References', $_reference_id);
         }
         // Add x-mailer
         if (!empty($email->refrence_id)) {
             $message->addCustomeHeader('X-Mailer', 'rtCamp-mail-lib');
             if ('comment' == $email->refrence_type) {
                 $comment = get_comment($email->refrence_id);
                 $post_id = $comment->comment_post_ID;
             } else {
                 $post_id = $email->refrence_id;
             }
             $new_message_id = rtmb_generate_message_id($post_id, $email->id);
             rtmb_add_message_id_in_ref_id($new_message_id, $reference_id, $post_id);
             $message->addCustomeHeader('Message-ID', $new_message_id);
         }
     }
     //$mail->setFrom($fromemail);
     $message->setSubject(stripslashes_deep(html_entity_decode($subject, ENT_QUOTES, 'UTF-8')));
     //$mail->setSubject($subject);
     if (!empty($toEmail)) {
         foreach ($toEmail as $temail) {
             //$mail->addTo($temail["email"], isset($temail["name"]) ? $temail["name"] : '');
             $message->addTo($temail['email'], isset($temail['name']) ? $temail['name'] : '');
         }
     }
     if (!empty($ccEmail)) {
         foreach ($ccEmail as $temail) {
             //$mail->addCc($temail["email"], isset($temail["name"]) ? $temail["name"] : '');
             $message->addCc($temail['email'], isset($temail['name']) ? $temail['name'] : '');
         }
     }
     if (!empty($bccEmail)) {
         foreach ($bccEmail as $temail) {
             if (isset($temail['email'])) {
                 $message->addBcc($temail['email'], isset($temail['name']) ? $temail['name'] : '');
             }
         }
     }
     // create a MimeMessage object that will hold the mail body and any attachments
     $bodyPart = new MimeMessage();
     $bodyMessage = new MimePart($body);
     $bodyMessage->type = 'text/html';
     $bodyMessage->encoding = Mime::ENCODING_QUOTEDPRINTABLE;
     $bodyPart->addPart($bodyMessage);
     if (!empty($attachemnts) && is_array($attachemnts)) {
         foreach ($attachemnts as $attach) {
             $file_array = explode('/', $attach);
             $fileName = $file_array[count($file_array) - 1];
             $attachment = new MimePart(file_get_contents($attach));
             $attachment->type = rtmb_get_mime_type($attach);
             $attachment->filename = $fileName;
             $attachment->encoding = Zend\Mime\Mime::ENCODING_BASE64;
             $attachment->disposition = Zend\Mime\Mime::DISPOSITION_ATTACHMENT;
             $bodyPart->addPart($attachment);
         }
     }
     $message->setBody($bodyPart);
     $transport->send($message);
     return true;
 }