public function process(ServerRequestInterface $request, DelegateInterface $delegate) : ResponseInterface
 {
     /* @var \PSR7Session\Session\SessionInterface $session */
     $session = $request->getAttribute(SessionMiddleware::SESSION_ATTRIBUTE);
     // Generate csrf token
     if (!$session->get('csrf')) {
         $session->set('csrf', md5(random_bytes(32)));
     }
     // Generate form and inject csrf token
     $form = new FormFactory($this->template->render('app::contact-form', ['token' => $session->get('csrf')]), $this->inputFilterFactory);
     // Validate form
     $validationResult = $form->validateRequest($request);
     if ($validationResult->isValid()) {
         // Get filter submitted values
         $data = $validationResult->getValues();
         $this->logger->notice('Sending contact mail to {from} <{email}> with subject "{subject}": {body}', $data);
         // Create the message
         $message = new Message();
         $message->setFrom($this->config['from'])->setReplyTo($data['email'], $data['name'])->setTo($this->config['to'])->setSubject('[xtreamwayz-contact] ' . $data['subject'])->setBody($data['body']);
         $this->mailTransport->send($message);
         // Display thank you page
         return new HtmlResponse($this->template->render('app::contact-thank-you'), 200);
     }
     // Display form and inject error messages and submitted values
     return new HtmlResponse($this->template->render('app::contact', ['form' => $form->asString($validationResult)]), 200);
 }
Exemple #2
0
 public function send($subject, $text, $to, $from = null)
 {
     if (!config('mail.enabled')) {
         return;
     }
     $message = new Message();
     $message->setSubject($subject);
     if ($from) {
         if (is_array($from)) {
             $message->setFrom($from[0], $from[1]);
         } else {
             $message->setFrom($from);
         }
     }
     $message->addTo($to);
     $content = '<html><head><title>' . $subject . '</title></head><body>' . $text . '</body></html>';
     $html = new Mime\Part($content);
     $html->setType(Mime\Mime::TYPE_HTML);
     $html->setCharset('utf-8');
     $mimeMessage = new Mime\Message();
     $mimeMessage->addPart($html);
     foreach ($this->attachments as $attachment) {
         $mimeMessage->addPart($attachment);
     }
     $message->setBody($mimeMessage);
     try {
         $transport = new SmtpTransport(new SmtpOptions(config('mail.options')));
         $transport->send($message);
     } catch (\Exception $e) {
         throw $e;
     }
     return $this;
 }
Exemple #3
0
 public function send($fromAddress, $fromName, $replyToAddress, $replyToName, $toAddress, $toName, $subject, array $mimeParts)
 {
     $mail = new Message();
     if ($fromAddress && $fromName) {
         $mail->setFrom($fromAddress, $fromName);
     } else {
         if ($fromAddress) {
             $mail->setFrom($fromAddress);
         }
     }
     if ($replyToAddress && $replyToName) {
         $mail->setReplyTo($replyToAddress, $replyToName);
     } else {
         if ($replyToAddress) {
             $mail->setReplyTo($replyToAddress);
         }
     }
     if ($toAddress && $toName) {
         $mail->setTo($toAddress, $toName);
     } else {
         if ($toAddress) {
             $mail->setTo($toAddress);
         }
     }
     $mail->setSubject($subject);
     $mail->setEncoding('utf-8');
     $mime = new MimeMessage();
     $mime->setParts($mimeParts);
     $mail->setBody($mime);
     $this->mailTransport->send($mail);
     $this->getEventManager()->trigger('send', $mail);
 }
 /**
  * Creates a new message with some of the fields populated.
  *
  * @return Message
  */
 private function newMessage()
 {
     /* @var $config ModuleOptions */
     $config = $this->serviceLocator->get('EscoMail\\Options');
     $this->message = new Message();
     $this->message->setFrom($config->getMailSendFrom(), $config->getMailSendFromName());
     return $this->message;
 }
 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);
 }
 protected function sendEmailAction()
 {
     $userTable = $this->getServiceLocator()->get('UserTable');
     if (true) {
         //$this->request->isPost()) {
         $subject = 'subject';
         //$this->request->getPost()->get('subject');
         $body = 'body';
         //$this->request->getPost()->get('body');
         $fromUserId = 1;
         //$this->user->id;
         $toUserId = 2;
         //$this->request->getPost()->get('toUserId');
         $fromUser = $userTable->getUser($fromUserId);
         $toUser = $userTable->getUser($toUserId);
         $mail = new Mail\Message();
         $mail->setFrom($fromUser->email, $fromUser->name);
         $mail->addTo($toUser->email, $toUser->name);
         $mail->setSubject($subject);
         $mail->setBody($body);
         $transport = new Mail\Transport\Sendmail();
         $transport->send($mail);
     }
     return true;
 }
 /**
  * Build Message
  *
  * @return MailMessage
  */
 public function buildMessage()
 {
     // prepare html body
     $htmlBody = $this->renderer->render($this->viewModel);
     // prepare text body
     $textBody = $this->buildTextBody($htmlBody);
     // prepare subject
     $subject = $this->buildSubject($htmlBody);
     // prepare html part
     $htmlPart = new MimePart($this->buildHtmlHeader() . $htmlBody . $this->buildHtmlFooter());
     $htmlPart->type = 'text/html';
     // prepare text part
     $textPart = new MimePart($textBody);
     $textPart->type = 'text/plain';
     // prepare mime message
     $mailBody = new MimeMessage();
     $mailBody->setParts(array($textPart, $htmlPart));
     // prepare message
     $this->message = new MailMessage();
     $this->message->setEncoding($this->encoding);
     $this->message->setFrom($this->senderMail, $this->senderName);
     $this->message->setSubject($subject);
     $this->message->setBody($mailBody);
     // return mailer
     return $this;
 }
 public function indexAction()
 {
     $form = $this->getServiceLocator()->get('form.contact');
     if ($this->getRequest()->isPost()) {
         $post = $this->getRequest()->getPost()->toArray();
         $form->setData($post);
         if ($form->isValid()) {
             $content = 'Name: ' . $post['name'] . "\n";
             $content .= 'Email: ' . $post['email'] . "\n";
             $content .= 'Message: ' . "\n" . $post['message'];
             $message = new Message();
             $message->addTo('*****@*****.**');
             $message->setSubject('MajorApps website contact');
             $message->setBody($content);
             $message->setFrom('*****@*****.**');
             /** @var Smtp $transport */
             $transport = $this->getServiceLocator()->get('mail.transport');
             $transport->send($message);
             // Fallback in-case email fails
             $content = '=======================================' . "\n" . date('Y-m-d H:i:s') . "\n" . $content . "\n" . '=======================================' . "\n";
             file_put_contents(__DIR__ . '/../../../../../data/message.txt', $content, FILE_APPEND);
             $this->flashMessenger()->addSuccessMessage('Message sent successfully');
             return $this->redirect()->toRoute('home');
         } else {
             $this->flashMessenger()->addErrorMessage('Message was not sent successfully');
         }
     }
     return new ViewModel(['form' => $form, 'jargon' => $this->getJargon(), 'features' => $this->getFeatures()]);
 }
Exemple #9
0
    /**
     * Sends award certificate
     *
     * @param \User\Model\Entity\User $user
     * @param array $exam
     * @param \ZendPdf\Document $pdf
     */
    public function sendCertificate($user, $exam, $pdf)
    {
        $translator = $this->services->get('translator');
        $mail = new Message();
        $mail->addTo($user->getEmail(), $user->getName());
        $text = 'You are genius!
You answered all the questions correctly.
Therefore we are sending you as a gratitude this free award certificate.

';
        // we create a new mime message
        $mimeMessage = new MimeMessage();
        // create the original body as part
        $textPart = new MimePart($text);
        $textPart->type = "text/plain";
        // add the pdf document as a second part
        $pdfPart = new MimePart($pdf->render());
        $pdfPart->type = 'application/pdf';
        $mimeMessage->setParts(array($textPart, $pdfPart));
        $mail->setBody($mimeMessage);
        $mail->setFrom('*****@*****.**', 'Slavey Karadzhov');
        $mail->setSubject($translator->translate('Congratulations: Here is your award certificate'));
        $transport = $this->services->get('mail-transport');
        $transport->send($mail);
    }
 /**
  * @inheritDoc
  */
 public static function fromWrappedMessage(MailWrappedMessage $wrappedMessage = null, $transport = null)
 {
     if (!$wrappedMessage instanceof MailWrappedMessage) {
         throw new MailWrapperSetupException('Not MailWrappedMessage');
     }
     $message = new Message();
     foreach ($wrappedMessage->getToRecipients() as $address) {
         $message->addTo($address);
     }
     foreach ($wrappedMessage->getCcRecipients() as $address) {
         $message->addCc($address);
     }
     foreach ($wrappedMessage->getBccRecipients() as $address) {
         $message->addBcc($address);
     }
     $message->setReplyTo($wrappedMessage->getReplyTo());
     $message->setFrom($wrappedMessage->getFrom());
     $message->setSubject($wrappedMessage->getSubject());
     if ($wrappedMessage->getContentText()) {
         $message->setBody($wrappedMessage->getContentText());
     }
     if ($wrappedMessage->getContentHtml()) {
         $html = new MimePart($wrappedMessage->getContentHtml());
         $html->type = "text/html";
         $message->setBody($body);
     }
     return $message;
 }
 public function sendCareerMail($sender, $recipient, $subject, $text, $filepath, $candidateName)
 {
     $result = false;
     try {
         //add attachment
         $text = new Mime\Part($text);
         $text->type = Mime\Mime::TYPE_TEXT;
         $text->charset = 'utf-8';
         $fileContent = fopen($filepath, 'r');
         $attachment = new Mime\Part($fileContent);
         $attachment->type = 'application/pdf';
         $attachment->filename = $candidateName;
         $attachment->disposition = Mime\Mime::DISPOSITION_ATTACHMENT;
         // Setting the encoding is recommended for binary data
         $attachment->encoding = Mime\Mime::ENCODING_BASE64;
         // then add them to a MIME message
         $mimeMessage = new Mime\Message();
         $mimeMessage->setParts(array($text, $attachment));
         // and finally we create the actual email
         $message = new Message();
         $message->setBody($mimeMessage);
         $message->setFrom($sender);
         $message->addTo($recipient);
         $message->setSubject($subject);
         // Send E-mail message
         $transport = new Sendmail('-f' . $sender);
         $transport->send($message);
         $result = true;
     } catch (\Exception $e) {
         $result = false;
     }
     // Return status
     return $result;
 }
Exemple #12
0
 private function sendEmail(array $listaEmailTo, array $listaEmailCC, $subject, $msg)
 {
     $renderer = $this->getServiceLocator()->get('ViewRenderer');
     $content = $renderer->render('email/template', array('msg' => nl2br($msg)));
     // make a header as html(template)
     $html = new MimePart($content);
     $html->type = "text/html";
     // make a image inline
     $image = new MimePart(fopen(__DIR__ . '\\..\\..\\..\\..\\Frota\\view\\email\\fundo_email_checkin.png', 'r'));
     $image->type = "image/jpeg";
     $image->id = "fundo_mail";
     $image->disposition = "inline";
     // build an email with a text(html) + image(inline)
     $body = new MimeMessage();
     $body->setParts(array($html, $image));
     // instance mail
     $mail = new Mail\Message();
     $mail->setBody($body);
     // will generate our code html from template.phtml
     $mail->setFrom($this->from['email'], utf8_decode($this->from['nome']));
     $mail->addTo($listaEmailTo);
     //$mail->addCc($listaEmailCC);
     $mail->setSubject(utf8_decode($subject));
     $transport = new Mail\Transport\Smtp($this->options);
     try {
         $transport->send($mail);
     } catch (RuntimeException $exc) {
         $this->logger->info('Erro ao enviar email para: ' . implode(',', $listaEmailTo) . ' erro: ' . $exc->getMessage() . "\n" . $exc->getTraceAsString());
         if ($exc->getMessage() == 'Could not open socket') {
             throw new Exception('O serviço de e-mail do MPM está indisponível no momento, a mensagem não foi enviada!');
         }
         throw new Exception("Não foi possível enviar a mensagem, ocorreu o seguinte erro: {$exc->getMessage()}!");
     }
 }
Exemple #13
0
 /**
  *
  */
 private function generateMessage()
 {
     //Reply to
     if ($this->config["defaults"]["reply_to"] && is_null($this->email->getReplyTo())) {
         $this->message->addReplyTo($this->config["defaults"]["reply_to"], $this->config["defaults"]["reply_to_name"]);
     }
     /*
      * Produce a list of template vars
      */
     $this->templateVars = array_merge($this->config["template_vars"], $this->email->toArray());
     //If not layout, use default
     if (!$this->email->getHtmlLayoutName()) {
         $this->email->setHtmlLayoutName($this->config["defaults"]["html_layout_name"]);
     }
     /*
      * If not sender, use default
      */
     if (!is_null($this->email->getFrom())) {
         $this->message->setFrom($this->email->getFrom(), $this->email->getFromName());
     } else {
         $this->message->setFrom($this->config["defaults"]["from_email"], $this->config["defaults"]["from_name"]);
     }
     /*
      * Force the mailing as header if we have a mailing
      */
     if (!is_null($this->mailing)) {
         $this->message->getHeaders()->addHeaderLine('X-Mailjet-Campaign', DEBRANOVA_HOST . '-mailing-' . $this->mailing->getId());
     }
 }
 /**
  * Add Action
  * <br/> Responsible for :
  *       <br/>In case Get verb  -> Display Add new Book Form
  *       <br/>In case Post verb -> Add new book details into Database
  *                                 After Submit Book Form
  * @return ViewModel add view
  */
 public function addAction()
 {
     $form = new BookForm();
     $form->get('submit')->setValue('Add');
     // Another way to set Submit button value
     // $form->get('submit')->setAttribute('value', 'Add');
     $request = $this->getRequest();
     // Check If request is Post verb
     if ($request->isPost()) {
         $book = new Book();
         $form->setInputFilter($book->getInputFilter());
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $book->exchangeArray($form->getData());
             $this->getBookTable()->saveBook($book);
             //Send an email when a new book Was Added
             $mail = new Mail\Message();
             $mail->setBody('A new Book called ' . $book->title . ' has been added.');
             $mail->setFrom('*****@*****.**', 'Zend course');
             $mail->addTo('*****@*****.**', 'Ahmed Hamdy');
             $mail->setSubject('A Book was Added');
             $transport = new Mail\Transport\Sendmail();
             $transport->send($mail);
         }
         // redirect to list of books
         return $this->redirect()->toRoute('book');
     }
     return new ViewModel(array('form' => $form));
 }
Exemple #15
0
 public function addAction()
 {
     $form = new BookForm();
     $form->get('submit')->setValue('Add');
     $request = $this->getRequest();
     if ($request->isPost()) {
         $book = new Book();
         $form->setInputFilter($book->getInputFilter());
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $book->exchangeArray($form->getData());
             $this->getBookTable()->saveBook($book);
             //send email
             $mail = new Mail\Message();
             $mail->setBody('A new book called ' . $book->title . ' has been added.');
             $mail->setFrom('*****@*****.**', 'Zend Course');
             $mail->addTo('*****@*****.**', 'Myself');
             $mail->setSubject('A Book was added');
             $transport = new Mail\Transport\Sendmail();
             $transport->send($mail);
         }
         //Redirect to books list
         return $this->redirect()->toRoute('book');
     }
     return array('form' => $form);
 }
 /**
  * Send email to contacts, insert message into db, log operation
  */
 public function sendAction()
 {
     $form = new ContactsForm();
     $request = $this->getRequest();
     if ($request->isPost()) {
         $mainLayout = $this->initializeFrontendWebsite();
         $em = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default');
         $inputFilter = new ContactsFormInputFilter();
         $form->setInputFilter($inputFilter->getInputFilter());
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $inputFilter->exchangeArray($form->getData());
             $formData = $request->getPost();
             $configurations = $this->layout()->getVariable('configurations');
             $mail = new Mail\Message();
             $mail->setFrom($configurations['emailnoreply'], $formData->nome . ' ' . $formData->cognome);
             $mail->addTo($configurations['emailcontact'], $configurations['sitename']);
             $mail->setSubject('Nuovo messaggio dal sito ' . $configurations['sitename']);
             $mail->setBody("Nome e cognome: \n " . $formData->nome . " " . $formData->cognome . " Email: " . $formData->email . "\n Messaggio: " . $formData->messaggio);
             $transport = new Mail\Transport\Sendmail();
             $transport->send($mail);
             $helper = new ContactsControllerHelper();
             $helper->setConnection($em->getConnection());
             $helper->insert($inputFilter);
             $this->layout()->setVariables(array('configuraitions' => $configurations, 'homepage' => !empty($homePageElements) ? $homePageElements : null, 'templatePartial' => 'contatti/ok.phtml'));
             $this->layout()->setTemplate($mainLayout);
         } else {
             foreach ($form->getInputFilter()->getInvalidInput() as $invalidInput) {
                 var_dump($form->getMessages());
             }
             exit;
         }
     }
 }
Exemple #17
0
 public function submitAction()
 {
     $result = "";
     $contact = $this->params()->fromPost();
     $captcha = new Captcha(array('name' => 'captcha', 'wordLen' => 6, 'timeout' => 600));
     if ($captcha->isValid($_POST['captcha'], $_POST)) {
         unset($contact['submit']);
         $contact = array_filter($contact);
         if ($contact && is_array($contact)) {
             $mail = new Mail\Message();
             $html = '<p>Contact from Kingsy.co.uk</p><p>=-=-=-=-=-=-=-=-=-=-=-=-=-=</p><p><span></span>From: <span>' . $contact["name"] . '</span></p><p><span></span>Email: <span>' . $contact["email"] . '</span></p><p><span></span>Content<p>' . $contact["content"] . '</p></p>';
             $mail->setFrom('*****@*****.**', 'Contact Form - Kingsy.co.uk')->addTo("*****@*****.**")->setSubject('Contacted');
             $bodyPart = new MimeMessage();
             $bodyMessage = new MimePart($html);
             $bodyMessage->type = 'text/html';
             $bodyPart->setParts(array($bodyMessage));
             $mail->setBody($bodyPart);
             $mail->setEncoding('UTF-8');
             try {
                 $transport = new Mail\Transport\Sendmail();
                 $transport->send($mail);
                 $result = true;
             } catch (Exception $e) {
                 print_r($e);
             }
         } else {
             $result = false;
         }
     } else {
         $result = false;
     }
     return new ViewModel(array('result' => $result));
 }
 /**
  * Sends the contact message via email
  *
  * @param array $data
  * @return boolean
  **/
 public function send($data)
 {
     $form = $this->getForm();
     $form->setData($data);
     if ($form->isValid()) {
         $data = $form->getData();
         $message = 'Name: ' . $data['name'] . "\r\n";
         $message .= 'Email: ' . $data['email'] . "\r\n\r\n";
         $message .= $data['comment'];
         $mail = new Message();
         $mail->setBody($message);
         $mail->setFrom('*****@*****.**');
         $mail->addTo('*****@*****.**', 'Rob Keplin');
         $mail->setSubject('From robkeplin.com');
         $transport = new Sendmail();
         try {
             $transport->send($mail);
         } catch (RuntimeException $e) {
             $this->addMessage('The email did not get sent due to sendmail failing. Doh!', self::MSG_ERROR);
             return false;
         }
         $form->setData(array('name' => '', 'email' => '', 'comment' => ''));
         $this->addMessage('Thanks.  Get back to you soon!', self::MSG_NOTICE);
         return true;
     }
     $this->addMessage('Hey, Wait! Something went wrong down there.  Please fix the errors and try again.', self::MSG_ERROR);
     return false;
 }
 protected function sendOfflineMessage($msgSubj, $msgText, $fromUserId, $toUserId)
 {
     $userTable = $this->getServiceLocator()->get('UserTable');
     $fromUser = $userTable->getById($fromUserId);
     $toUser = $userTable->getById($toUserId);
     $mail = new Mail\Message();
     $mail->setFrom($fromUser->getEmail(), $fromUser->getName());
     $mail->addTo($toUser->getEmail(), $toUser->getName());
     $mail->setSubject($msgSubj);
     $mail->setBody($msgText);
     $transport = new Mail\Transport\Sendmail();
     //        $transport = new Mail\Transport\Smtp();
     //        $options   = new Mail\Transport\SmtpOptions(array(
     //            'name'              => 'smtp.gmail.com',
     //            'host'              => 'smtp.gmail.com',
     //            'connection_class'  => 'login',
     //            'connection_config' => array(
     //                'ssl'      => 'tls',
     //                'username' => '*****@*****.**',
     //                'password' => '',
     //            ),
     //        ));
     //        $transport->setOptions($options);
     $transport->send($mail);
     return true;
 }
Exemple #20
0
 /**
  * @param Message $message
  */
 public function send(Message $message)
 {
     if (!count($message->getFrom())) {
         $message->setFrom('*****@*****.**', 'US Canine Scent Sports');
     }
     $transport = new Transport\Smtp();
     $transport->setOptions($this->transportOptions)->send($message);
 }
 /**
  * Gets a mail message with some of the fields populated.
  * @return Message
  */
 public function getMessage()
 {
     /** @var MessageConfig $messageConfig */
     $messageConfig = $this->serviceLocator->get('mail_message_config');
     $mail = new Message();
     $mail->setFrom($messageConfig->getFrom(), $messageConfig->getFromName());
     return $mail;
 }
Exemple #22
0
 public function setFrom($emailOrAddressList = null, $name = null)
 {
     if ($emailOrAddressList == null && $name == null) {
         $emailOrAddressList = $this->mailMessageConfigObj->getFrom();
         $name = $this->mailMessageConfigObj->getFromName();
     }
     parent::setFrom($emailOrAddressList, $name);
     return $this;
 }
Exemple #23
0
 /**
  * @expectedException \Mandrill_Invalid_Key
  */
 public function testSendObject()
 {
     $message = new Message();
     $body = new ToStringObject();
     $body->addElement('one')->addElement('two')->addElement('three');
     $message->setBody($body);
     $message->setFrom('*****@*****.**');
     $this->mandrill->send($message);
 }
Exemple #24
0
 public function sendInvoiceWithParams(Invoice $invoice, Parameters $data)
 {
     $message = new Message();
     $message->setTo($data->to);
     $message->setFrom($data->from);
     $message->setSubject($data->header);
     $message->setBody($data->content);
     $parts[] = $this->getAttachment($data->file, $data->fileName);
     $this->send($data->transport, $message, $parts);
 }
 /**
  * Dispara um e-mail conforme as configurações fornecidas.
  *
  * @param string $name    Nome do remetente
  * @param string $email   E-mail do remetente
  * @param string $subject Assunto do e-mail
  * @param string $message Conteúdo a ser enviado
  */
 public function sendEmail($name, $email, $subject, $message)
 {
     $mail = new Mail\Message();
     $mail->addTo($email, $name);
     $mail->setFrom('*****@*****.**', 'MPRecruiter');
     $mail->setSubject($subject);
     $mail->setBody($message);
     $transport = new Mail\Transport\Sendmail();
     $transport->send($mail);
 }
Exemple #26
0
 public function sendMail($from, $name, $message)
 {
     $mail = new Message();
     $mail->setBody($message);
     $mail->setFrom($from, $name);
     $mail->setTo(self::EMAIL_ADMIN, 'Their name');
     $mail->setSubject('Test Subject');
     //Todo config le smtp
     //        $transport = new Transport\Sendmail();
     //        $transport->send($mail);
 }
Exemple #27
0
 public function testCanSetFromListFromAddressList()
 {
     $list = new AddressList();
     $list->add('*****@*****.**');
     $this->message->addFrom('*****@*****.**');
     $this->message->setFrom($list);
     $from = $this->message->getFrom();
     $this->assertEquals(1, count($from));
     $this->assertFalse($from->has('*****@*****.**'));
     $this->assertTrue($from->has('*****@*****.**'));
 }
 /**
  * @param TodoAssigneeWasReminded $event
  */
 public function __invoke(TodoAssigneeWasReminded $event)
 {
     $user = $this->userFinder->findById($event->userId()->toString());
     $todo = $this->todoFinder->findById($event->todoId()->toString());
     $mail = new Mail\Message();
     $mail->setBody("Hello {$user->name}. This a reminder for '{$todo->text}'. Don't be lazy!");
     $mail->setFrom('*****@*****.**', 'Proophessor-do');
     $mail->addTo($user->email, $user->name);
     $mail->setSubject('Proophessor-do Todo Reminder');
     $this->mailer->send($mail);
 }
Exemple #29
0
 /**
  * @param  string  $tpl
  * @param  array   $data
  * @return Message
  */
 public function getMessage($tpl, array $data)
 {
     $mail = new Message();
     $mail->setEncoding('UTF-8');
     if (isset($data['encoding'])) {
         $mail->setEncoding($data['encoding']);
     }
     if (isset($data['from_address'])) {
         if (isset($data['from_name'])) {
             $mail->setFrom($data['from_address'], $data['from_name']);
         } else {
             $mail->setFrom($data['from_address']);
         }
     }
     if (isset($data['to'])) {
         if (isset($data['to_name'])) {
             $mail->setTo($data['to'], $data['to_name']);
         } else {
             $mail->setTo($data['to']);
         }
     }
     if (isset($data['cc'])) {
         $mail->setCc($data['cc']);
     }
     if (isset($data['bcc'])) {
         $mail->setBcc($data['bcc']);
     }
     if (isset($data['subject'])) {
         $mail->setSubject($data['subject']);
     }
     if (isset($data['sender'])) {
         $mail->setSender($data['sender']);
     }
     if (isset($data['replyTo'])) {
         $mail->setReplyTo($data['replyTo']);
     }
     $content = $this->renderMail($tpl, $data);
     $mail->setBody($content);
     $mail->getHeaders()->addHeaderLine('Content-Type', 'text/html; charset=UTF-8')->addHeaderLine('Content-Transfer-Encoding', '8bit');
     return $mail;
 }
 /**
  * Search POSTED user email, send email with request to regenerate password or choose a new one
  *
  * @return mixed
  */
 public function sendrecoverrequestAction()
 {
     /**
      * @var \Doctrine\ORM\EntityManager $em
      */
     $em = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default');
     $request = $this->getRequest();
     if (!$request->isPost()) {
         return $this->redirect()->toRoute('main');
     }
     $post = $request->getPost()->toArray();
     $inputFilter = new RecoverPasswordFormInputFilter();
     $form = new RecoverPasswordForm();
     $form->setInputFilter($inputFilter->getInputFilter());
     $form->setData($post);
     $helper = new UsersControllerHelper();
     $helper->setConnection($em->getConnection());
     if ($form->isValid()) {
         $userRecords = $helper->recoverWrapperRecords(new UsersGetterWrapper(new UsersGetter($em)), array('emailUsername' => $post['email'], 'limit' => 1));
         if (!empty($userRecords) and count($userRecords) == 1) {
             $confirmCode = md5(uniqid());
             $helper->updateConfirmCode($userRecords[0]['id'], $confirmCode);
             $uri = $request->getUri();
             $basePath = sprintf('%s://%s%s', $uri->getScheme(), $uri->getHost(), '');
             $linkRecoverPasswordForm = $basePath . $this->url()->fromRoute('recover-password', array('action' => 'formchangepassword', 'confirmcode' => $confirmCode));
             $appServiceLoader = $this->recoverAppServiceLoader(1);
             $configurations = $appServiceLoader->recoverService('configurations');
             $noReplayMail = isset($configurations['mailnoreply']) ? $configurations['mailnoreply'] : '*****@*****.**';
             $message = $configurations['sitename'] . "\n\n";
             $message .= "E' stata registrata una richiesta di recupero password per il sito in oggetto.\n\n";
             $message .= 'Per scegliere una nuova password, <a href="' . $linkRecoverPasswordForm . '">clicca qui</a>' . "\n\n";
             $message .= "Se non vedi il link, conferma la richiesta copiando e incollando il link sotto riportato sul tuo browser:\n\n";
             $message .= $linkRecoverPasswordForm . "\n\n";
             $message .= 'Non rispondere a questo messaggio' . "\n\n";
             $message .= date("Y") . ' ' . $configurations['sitename'];
             /* Send email with link for password recover */
             $mail = new Mail\Message();
             $mail->setBody($message);
             $mail->setFrom($noReplayMail, $configurations['sitename']);
             $mail->addTo($userRecords[0]['email'], $userRecords[0]['name'] . ' ' . $userRecords[0]['surname']);
             $mail->setSubject('Richiesta recupero password ', $configurations['sitename']);
             $transport = new Mail\Transport\Sendmail($userRecords[0]['email']);
             $transport->send($mail);
             /* Redirect to another page with OK message to avoid double POSTs */
             return $this->redirect()->toRoute('recover-password', array('action' => 'showconfirm', 'confirmcode' => 'passwordRequestSentOk'));
         } else {
             // User not found, invalid request...
         }
     } else {
         // The form is not valid, it can redirect to a confirm message page
     }
     return $this->redirect()->toRoute('main');
 }