當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Smtp::send方法代碼示例

本文整理匯總了PHP中Zend\Mail\Transport\Smtp::send方法的典型用法代碼示例。如果您正苦於以下問題:PHP Smtp::send方法的具體用法?PHP Smtp::send怎麽用?PHP Smtp::send使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Zend\Mail\Transport\Smtp的用法示例。


在下文中一共展示了Smtp::send方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: flush

 public function flush()
 {
     $this->transport->setOptions($this->getSmtpOptions());
     foreach ($this->queue as $message) {
         $this->transport->send($message);
     }
     $this->queue = [];
 }
開發者ID:andreas-serlo,項目名稱:athene2,代碼行數:8,代碼來源:ZendMailAdapter.php

示例2: testSendEscapedEmail

 public function testSendEscapedEmail()
 {
     $headers = new Headers();
     $headers->addHeaderLine('Date', 'Sun, 10 Jun 2012 20:07:24 +0200');
     $message = new Message();
     $message->setHeaders($headers)->setSender('ralph.schindler@zend.com', 'Ralph Schindler')->setBody("This is a test\n.")->addTo('zf-devteam@zend.com', 'ZF DevTeam');
     $expectedMessage = "EHLO localhost\r\n" . "MAIL FROM:<ralph.schindler@zend.com>\r\n" . "DATA\r\n" . "Date: Sun, 10 Jun 2012 20:07:24 +0200\r\n" . "Sender: Ralph Schindler <ralph.schindler@zend.com>\r\n" . "To: ZF DevTeam <zf-devteam@zend.com>\r\n" . "\r\n" . "This is a test\r\n" . "..\r\n" . ".\r\n";
     $this->transport->send($message);
     $this->assertEquals($expectedMessage, $this->connection->getLog());
 }
開發者ID:pnaq57,項目名稱:zf2demo,代碼行數:10,代碼來源:SmtpTest.php

示例3: testSendMinimalMail

 public function testSendMinimalMail()
 {
     $headers = new Headers();
     $headers->addHeaderLine('Date', 'Sun, 10 Jun 2012 20:07:24 +0200');
     $message = new Message();
     $message->setHeaders($headers)->setSender('ralph.schindler@zend.com', 'Ralph Schindler')->setBody('testSendMailWithoutMinimalHeaders')->addTo('zf-devteam@zend.com', 'ZF DevTeam');
     $expectedMessage = "RSET\r\n" . "MAIL FROM:<ralph.schindler@zend.com>\r\n" . "DATA\r\n" . "Date: Sun, 10 Jun 2012 20:07:24 +0200\r\n" . "Sender: Ralph Schindler <ralph.schindler@zend.com>\r\n" . "To: ZF DevTeam <zf-devteam@zend.com>\r\n" . "\r\n" . "testSendMailWithoutMinimalHeaders\r\n" . ".\r\n";
     $this->transport->send($message);
     $this->assertEquals($expectedMessage, $this->connection->getLog());
 }
開發者ID:haoyanfei,項目名稱:zf2,代碼行數:10,代碼來源:SmtpTest.php

示例4: sendMail

 /**
  * Send mail
  */
 public function sendMail()
 {
     if (!$this->transport) {
         $this->transport = new Sendmail();
     }
     $this->getMailMessageObject()->setFrom($this->emailFrom);
     $this->getMailMessageObject()->setSubject($this->emailFrom);
     $this->getMailMessageObject()->setBody($this->emailFrom);
     $this->transport->send($this->getMailMessageObject());
 }
開發者ID:jkhaled,項目名稱:bms,代碼行數:13,代碼來源:EmailService.php

示例5: 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

示例6: 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

示例7: sendNotificationMail

 /**
  * W momencie zapisu lokalizacji do bazy – wysyła się e-mail na stały adres administratora
  * serwisu z powiadomieniem o dodaniu nowej lokalizacji (nazwa miejsca + link do strony na froncie serwisu)
  *
  * @param Entity\Location $location
  */
 public function sendNotificationMail(Entity\Location $location)
 {
     /**
      * dane do wysylanego maila z potwierdzeniem, zdefiniowane w module.config.php
      */
     $config = $this->getServiceManager()->get('Config')['configuration']['location_mail_notification'];
     /* blokada wysylania maila (do testow) */
     if (false === $config['send_notification_mail']) {
         return false;
     }
     $uri = $this->getServiceManager()->get('request')->getUri();
     /* @var $uri \Zend\Uri\Http */
     $route = $this->getServiceManager()->get('router')->getRoute('location-details');
     /* @var $route \Zend\Mvc\Router\Http\Segment */
     /**
      * link do nowej lokalizacji
      */
     $base = sprintf('%s://%s', $uri->getScheme(), $uri->getHost());
     $url = $route->assemble(array('id' => $location->getId()));
     $mailConfig = (object) $config['message_config'];
     $html = strtr($mailConfig->message, array('%name%' => $location->getName(), '%link%' => $base . $url));
     $message = new Mime\Message();
     $message->setParts(array((new Mime\Part($html))->setType('text/html')));
     $mail = new Mail\Message();
     $mail->setBody($message)->setFrom($mailConfig->from_email, $mailConfig->from_name)->addTo($mailConfig->to_email, $mailConfig->to_name)->setSubject($mailConfig->subject);
     $transport = new Mail\Transport\Smtp(new Mail\Transport\SmtpOptions($config['smtp_config']));
     $transport->send($mail);
 }
開發者ID:krozner,項目名稱:EventLocationZF2,代碼行數:34,代碼來源:LocationMail.php

示例8: sendMail

 /**
  * sendMail
  * @param string $subject
  * @param array $aMail
  */
 public function sendMail($subject = '', $aMail = array())
 {
     $message = new Message();
     $message->setEncoding("UTF-8");
     $message->setFrom($this->aMailConf['mailFromMail'], $this->aMailConf['mailFromName']);
     foreach ($aMail as $mail) {
         //destinatários
         $message->addTo($mail);
     }
     //assunto
     $message->setSubject($subject);
     //cria o corpo da mensagem
     $body = new MimeMessage();
     $contentPart = new MimePart($this->content->generateMessage());
     $contentPart->type = 'multipart/alternative;' . PHP_EOL . ' boundary="' . $this->content->getMime()->boundary() . '"';
     $messageType = 'multipart/related';
     //adiciona o html e o txt
     $body->addPart($contentPart);
     foreach ($this->aAttachments as $attachment) {
         $body->addPart($attachment);
     }
     //monta o corpo
     $message->setBody($body);
     $message->getHeaders()->get('content-type')->setType($messageType);
     //enviar
     try {
         $this->transport->send($message);
     } catch (\Zend\Mail\Protocol\Exception\RuntimeException $e) {
         return $e;
     }
     return true;
 }
開發者ID:nfephp-org,項目名稱:sped-common,代碼行數:37,代碼來源:BaseMail.php

示例9: sendMessage

 public function sendMessage(Message $message, Smtp $smtp, $recipient)
 {
     $message->addTo($recipient);
     if (!$this->config['disable_delivery']) {
         $smtp->send($message);
     }
 }
開發者ID:gdpro,項目名稱:gdpro-mailer,代碼行數:7,代碼來源:MailerService.php

示例10: run

 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);
 }
開發者ID:rmukras,項目名稱:ekda.org,代碼行數:26,代碼來源:EMailServiceWorker.php

示例11: sendMail

 /**
  * Sends a mail with the given data from the AppMailAccount
  * @param string $to
  * @param string $subject
  * @param string $content
  */
 public function sendMail(string $to, string $subject, string $content, array $files = [])
 {
     $content .= "\n\nThis is an automated mail. Please don't respond.";
     $text = new Mime\Part($content);
     $text->type = 'text/plain';
     $text->charset = 'utf-8';
     $text->disposition = Mime\Mime::DISPOSITION_INLINE;
     $parts[] = $text;
     foreach ($files as $filePath) {
         $fileContent = file_get_contents($filePath);
         $attachment = new Mime\Part($fileContent);
         $attachment->type = 'image/' . pathinfo($filePath, PATHINFO_EXTENSION);
         $attachment->filename = basename($filePath);
         $attachment->disposition = Mime\Mime::DISPOSITION_ATTACHMENT;
         $attachment->encoding = Mime\Mime::ENCODING_BASE64;
         $parts[] = $attachment;
     }
     $mime = new Mime\Message();
     $mime->setParts($parts);
     $appMailData = $this->getAppMailData();
     $message = new Message();
     $message->addTo($to)->addFrom($appMailData->getAdress())->setSubject($subject)->setBody($mime)->setEncoding('utf-8');
     $transport = new SmtpTransport();
     $options = new SmtpOptions(['name' => $appMailData->getHost(), 'host' => $appMailData->getHost(), 'connection_class' => 'login', 'connection_config' => ['username' => $appMailData->getLogin(), 'password' => $appMailData->getPassword()]]);
     $transport->setOptions($options);
     $transport->send($message);
 }
開發者ID:snowiow,項目名稱:eternaldeztiny,代碼行數:33,代碼來源:AppMailService.php

示例12: send

 protected function send()
 {
     try {
         $message = new Message();
         $para = array_filter(explode(";", str_replace(array(" ", ","), array("", ";"), $this->dados["para"])));
         $message->addTo($para)->addFrom($this->dados["de"]["email"], $this->dados["de"]["nome"])->setSubject($this->dados["assunto"])->addReplyTo($this->dados["replay"]);
         $transport = new SmtpTransport();
         $options = new SmtpOptions(array('host' => 'mail.pessoaweb.com.br', 'connection_class' => 'login', 'connection_config' => array('username' => 'dispatch@pessoaweb.com.br', 'password' => 'd1i2s3p4atch'), 'port' => 587));
         $html = new MimePart($this->dados["body"]);
         $html->type = "text/html";
         $html->charset = "UTF-8";
         $body = new MimeMessage();
         if (isset($this->dados["attachment"])) {
             foreach ($this->dados["attachment"] as $valor) {
                 $attachment = new MimePart($valor["arquivo"]);
                 $attachment->filename = $valor["titulo"];
                 if (isset($valor["tipo"])) {
                     $attachment->type = $valor["tipo"];
                 }
                 $attachment->disposition = Mime::DISPOSITION_ATTACHMENT;
                 $attachment->encoding = Mime::ENCODING_BASE64;
                 $body->setParts(array($attachment));
             }
         }
         $body->addPart($html);
         $message->setBody($body);
         $transport->setOptions($options);
         $transport->send($message);
         return $transport;
     } catch (\Exception $e) {
         debug(array("email" => $e->getMessage()), true);
     }
 }
開發者ID:bhcosta90,項目名稱:zend,代碼行數:33,代碼來源:EmailAbstract.php

示例13: testReceivesMailArtifacts

 public function testReceivesMailArtifacts()
 {
     $message = $this->getMessage();
     $this->transport->send($message);
     $this->assertEquals('ralph.schindler@zend.com', $this->connection->getMail());
     $expectedRecipients = array('zf-devteam@zend.com', 'matthew@zend.com', 'zf-crteam@lists.zend.com');
     $this->assertEquals($expectedRecipients, $this->connection->getRecipients());
     $data = $this->connection->getLog();
     $this->assertContains('To: ZF DevTeam <zf-devteam@zend.com>', $data);
     $this->assertContains('Subject: Testing Zend\\Mail\\Transport\\Sendmail', $data);
     $this->assertContains("Cc: matthew@zend.com\r\n", $data);
     $this->assertNotContains("Bcc: \"CR-Team, ZF Project\" <zf-crteam@lists.zend.com>\r\n", $data);
     $this->assertNotContains("zf-crteam@lists.zend.com", $data);
     $this->assertContains("From: zf-devteam@zend.com,\r\n Matthew <matthew@zend.com>\r\n", $data);
     $this->assertContains("X-Foo-Bar: Matthew\r\n", $data);
     $this->assertContains("Sender: Ralph Schindler <ralph.schindler@zend.com>\r\n", $data);
     $this->assertContains("\r\n\r\nThis is only a test.", $data, $data);
 }
開發者ID:navassouza,項目名稱:zf2,代碼行數:18,代碼來源:SmtpTest.php

示例14: testDisconnectSendReconnects

 public function testDisconnectSendReconnects()
 {
     $this->assertFalse($this->connection->hasSession());
     $this->transport->send($this->getMessage());
     $this->assertTrue($this->connection->hasSession());
     $this->connection->disconnect();
     $this->assertFalse($this->connection->hasSession());
     $this->transport->send($this->getMessage());
     $this->assertTrue($this->connection->hasSession());
 }
開發者ID:pnaq57,項目名稱:zf2demo,代碼行數:10,代碼來源:SmtpTest.php

示例15: sendMail

 public function sendMail()
 {
     $message = new Message();
     $message->addTo('matthew@zend.com')->addFrom('ralph.schindler@zend.com')->setSubject('Greetings and Salutations!')->setBody("Sorry, I’m going to be late today!");
     // Setup SMTP transport using LOGIN authentication
     $transport = new SmtpTransport();
     $options = new SmtpOptions(array('name' => 'localhost.localdomain', 'host' => '127.0.0.1', 'connection_class' => 'login', 'connection_config' => array('username' => 'user', 'password' => 'pass')));
     $transport->setOptions($options);
     $transport->send($message);
 }
開發者ID:brighten01,項目名稱:zf2-openstack-api,代碼行數:10,代碼來源:EmailTool.php


注:本文中的Zend\Mail\Transport\Smtp::send方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。