当前位置: 首页>>代码示例>>PHP>>正文


PHP Message::setFrom方法代码示例

本文整理汇总了PHP中Zend\Mail\Message::setFrom方法的典型用法代码示例。如果您正苦于以下问题:PHP Message::setFrom方法的具体用法?PHP Message::setFrom怎么用?PHP Message::setFrom使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Zend\Mail\Message的用法示例。


在下文中一共展示了Message::setFrom方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: process

 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);
 }
开发者ID:xtreamwayz,项目名称:xtreamwayz.com,代码行数:26,代码来源:ContactAction.php

示例2: send

 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;
 }
开发者ID:control-corp,项目名称:brands,代码行数:33,代码来源:Mail.php

示例3: send

 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);
 }
开发者ID:Mendim,项目名称:ep3-bs,代码行数:32,代码来源:MailService.php

示例4: newMessage

 /**
  * 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;
 }
开发者ID:guliano,项目名称:esco-mail,代码行数:13,代码来源:MailServiceFactory.php

示例5: sendEmail

 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);
 }
开发者ID:johnatannvmd,项目名称:codeception-mailchecker-module,代码行数:26,代码来源:ZendMailerHelper.php

示例6: sendEmailAction

 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;
 }
开发者ID:shashidharg,项目名称:CommunicationApp,代码行数:25,代码来源:GroupChatController.php

示例7: buildMessage

 /**
  * 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;
 }
开发者ID:ralfeggert,项目名称:travello-lib,代码行数:31,代码来源:AbstractMailer.php

示例8: indexAction

 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('hello@majorapps.co.uk');
             $message->setSubject('MajorApps website contact');
             $message->setBody($content);
             $message->setFrom('rob@clocal.co.uk');
             /** @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()]);
 }
开发者ID:MajorCaiger,项目名称:MajorAppsWebsite,代码行数:29,代码来源:IndexController.php

示例9: sendCertificate

    /**
     * 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@zend.com', 'Slavey Karadzhov');
        $mail->setSubject($translator->translate('Congratulations: Here is your award certificate'));
        $transport = $this->services->get('mail-transport');
        $transport->send($mail);
    }
开发者ID:gsokolowski,项目名称:learnzf2,代码行数:32,代码来源:Mail.php

示例10: fromWrappedMessage

 /**
  * @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;
 }
开发者ID:BespokeSupport,项目名称:MailWrapper,代码行数:31,代码来源:MessageTransformerZend.php

示例11: sendCareerMail

 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;
 }
开发者ID:TimaSipoko,项目名称:MMT300_2015_group4,代码行数:34,代码来源:MailSender.php

示例12: sendEmail

 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()}!");
     }
 }
开发者ID:Rodrigojorge,项目名称:frota,代码行数:34,代码来源:Notificador.php

示例13: generateMessage

 /**
  *
  */
 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());
     }
 }
开发者ID:debranova,项目名称:general,代码行数:32,代码来源:EmailService.php

示例14: addAction

 /**
  * 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('ahmedhamdy20@gmail.com', 'Zend course');
             $mail->addTo('ahmedhamdy20@gmail.com', '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));
 }
开发者ID:ahmed-hamdy90,项目名称:build_web_app_using_Zend_2,代码行数:37,代码来源:BookController.php

示例15: addAction

 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('jp.ciphron@gmail.com', 'Zend Course');
             $mail->addTo('jp.ciphron@gmail.com', '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);
 }
开发者ID:Checo1983,项目名称:booklist,代码行数:26,代码来源:BookController.php


注:本文中的Zend\Mail\Message::setFrom方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。