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


PHP Swift_SmtpTransport::newInstance方法代码示例

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


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

示例1: createAction

 /**
  * Creates a new Mensaje entity.
  *
  */
 public function createAction(Request $request)
 {
     $entity = new Mensaje();
     $form = $this->createCreateForm($entity);
     $form->handleRequest($request);
     $em = $this->getDoctrine()->getManager();
     $categorias = $em->getRepository('GulloaStoreBackendBundle:Categoria')->findAll();
     if ($form->isValid()) {
         $emailname = 'no.reply.gulloadev';
         $emailpass = 'pass68029595';
         $transport = \Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, "ssl")->setUsername($emailname)->setPassword($emailpass)->setSourceIp('0.0.0.0');
         $asunto = $entity->getAsunto();
         $datos = $em->getRepository('GulloaStoreBackendBundle:Datos')->find(1);
         $mensaje = $this->renderView('GulloaStoreBackendBundle:Mail:mensaje.html.twig', array('entity' => $entity));
         $message = \Swift_Message::newInstance()->setSubject('[GulloaStore] ' . $asunto)->setFrom('no.reply.gulloadev@gmail.com')->setTo($datos->getEmail())->setBody($mensaje, 'text/html');
         $mailer = \Swift_Mailer::newInstance($transport);
         $mailer->send($message);
         $this->addFlash('mailing', 'Mensaje enviado correctamente');
         $entity->setLeido(0)->setFecha(new \DateTime('now'));
         $em->persist($entity);
         $em->flush();
         return $this->redirect($this->generateUrl('mensaje'));
     }
     return $this->render('GulloaStoreBackendBundle:Tipo:new.html.twig', array('entity' => $entity, 'form' => $form->createView(), 'categorias' => $categorias));
 }
开发者ID:gsulloa,项目名称:gulloaStore,代码行数:29,代码来源:MensajeController.php

示例2: sendEmail

 /**
  * Send email using swift api.
  * 
  * @param $body
  * @param $recipients
  * @param $from
  * @param $subject
  */
 public function sendEmail($body, $recipients, $from, $subject)
 {
     $config = Zend_Registry::get('config');
     $failures = '';
     Swift_Preferences::getInstance()->setCharset('UTF-8');
     //Create the Transport
     $transport = Swift_SmtpTransport::newInstance($config->mail->server->name, $config->mail->server->port, $config->mail->server->security)->setUsername($config->mail->username)->setPassword($config->mail->password);
     $mailer = Swift_Mailer::newInstance($transport);
     $message = Swift_Message::newInstance();
     $headers = $message->getHeaders();
     $headers->addTextHeader("signed-by", Constant::EMAIL_DOMAIN);
     //Give the message a subject
     $message->setSubject($subject);
     //Set the From address with an associative array
     $message->setFrom($from);
     //Set the To addresses with an associative array
     $message->setTo($recipients);
     //Give it a body
     $message->setBody($body);
     $message->setContentType("text/html");
     //Send the message
     $myresult = $mailer->batchSend($message);
     if ($myresult) {
         return null;
     } else {
         return Constant::EMAIL_FAIL_MESSAGE;
     }
 }
开发者ID:BGCX262,项目名称:zufangzi-svn-to-git,代码行数:36,代码来源:SwiftEmail.php

示例3: connect

 /**
  * Creates a SwiftMailer instance.
  *
  * @param   string  DSN connection string
  * @return  object  Swift object
  */
 public static function connect($config = NULL)
 {
     // Load default configuration
     $config === NULL and $config = Kohana::$config->load('email');
     switch ($config['driver']) {
         case 'smtp':
             // Set port
             $port = empty($config['options']['port']) ? 25 : (int) $config['options']['port'];
             // Create SMTP Transport
             $transport = Swift_SmtpTransport::newInstance($config['options']['hostname'], $port);
             if (!empty($config['options']['encryption'])) {
                 // Set encryption
                 $transport->setEncryption($config['options']['encryption']);
             }
             // Do authentication, if part of the DSN
             empty($config['options']['username']) or $transport->setUsername($config['options']['username']);
             empty($config['options']['password']) or $transport->setPassword($config['options']['password']);
             // Set the timeout to 5 seconds
             $transport->setTimeout(empty($config['options']['timeout']) ? 5 : (int) $config['options']['timeout']);
             break;
         case 'sendmail':
             // Create a sendmail connection
             $transport = Swift_SendmailTransport::newInstance(empty($config['options']) ? "/usr/sbin/sendmail -bs" : $config['options']);
             break;
         default:
             // Use the native connection
             $transport = Swift_MailTransport::newInstance();
             break;
     }
     // Create the SwiftMailer instance
     return self::$_mail = Swift_Mailer::newInstance($transport);
 }
开发者ID:rrsc,项目名称:beansbooks,代码行数:38,代码来源:core.php

示例4: __invoke

 /**
  * Create an object
  *
  * @param  ContainerInterface $container
  * @param  string $requestedName
  * @param  null|array $options
  * @return object|\Swift_Mailer
  * @throws ServiceNotFoundException if unable to resolve the service.
  * @throws ServiceNotCreatedException if an exception is raised when
  *     creating a service.
  * @throws ContainerException if any other error occurs
  */
 public function __invoke(ContainerInterface $container, $requestedName, array $options = null) : \Swift_Mailer
 {
     $mailConfig = $container->get('config')['mail'];
     $smtp = $mailConfig['smtp'];
     $transport = \Swift_SmtpTransport::newInstance($smtp['server'], $smtp['port'], $smtp['ssl'])->setUsername($smtp['username'])->setPassword($smtp['password']);
     return new \Swift_Mailer($transport);
 }
开发者ID:acelaya,项目名称:alejandrocelaya.com,代码行数:19,代码来源:SwiftMailerFactory.php

示例5: register

 public function register(Container $container)
 {
     $host = Config::get('mail.smtp.host');
     $port = Config::get('mail.smtp.port');
     $encryption = Config::get('mail.smtp.encryption');
     $username = Config::get('mail.smtp.username');
     $password = Config::get('mail.smtp.password');
     // The Swift SMTP transport instance will allow us to use any SMTP backend
     // for delivering mail such as Sendgrid, Amazon SMS, or a custom server
     // a developer has available. We will just pass the configured host.
     $transport = SmtpTransport::newInstance($host, $port);
     if (isset($encryption)) {
         $transport->setEncryption($encryption);
     }
     // Once we have the transport we will check for the presence of a username
     // and password. If we have it we will set the credentials on the Swift
     // transporter instance so that we'll properly authenticate delivery.
     if (isset($username)) {
         $transport->setUsername($username);
         $transport->setPassword($password);
     }
     $mailer = new Mailer(new Swift_Mailer($transport));
     $mailer->alwaysFrom(Config::get('mail.from.email'), Config::get('mail.from.name'));
     $container->mail = $mailer;
 }
开发者ID:kiasaki,项目名称:vexillum,代码行数:25,代码来源:MailProvider.php

示例6: notifyAction

 public function notifyAction()
 {
     $id = 1;
     $settings = R::load('settings', $id);
     $time_before = c::now()->modify('+' . $settings->time_before)->toDateString();
     $transport = \Swift_SmtpTransport::newInstance($settings->mail_host, $settings->mail_port)->setUsername($settings->mail_username)->setPassword($settings->mail_password);
     $mailer = \Swift_Mailer::newInstance($transport);
     $client = new \Services_Twilio($settings->twilio_sid, $settings->twilio_token);
     $recepients = R::findAll('recepients');
     $events = R::find("events", "is_enabled = 1 AND date = '{$time_before}'");
     foreach ($events as $event) {
         foreach ($recepients as $recepient) {
             $subject = preg_replace(array('/{title}/', '/{date}/'), array($event->title, $event->date), $settings->subject);
             $end_date = c::parse($event->date)->modify('+' . $event->days . ' days')->toDateString();
             $body_patterns = array('/{name}/', '/{title}/', '/{start_date}/', '/<!(\\w+) ({\\w+})>/');
             $body_replacements = array($settings->name, $event->title, $event->date, "\$1 {$end_date}");
             if ($event->days == 1) {
                 $body_replacements[3] = '';
             }
             $body = preg_replace($body_patterns, $body_replacements, $settings->msg_template);
             if ($recepient->email && $settings->mail_username && $settings->mail_password) {
                 $message = \Swift_Message::newInstance()->setSubject($subject)->setBody($body)->setFrom(array($settings->email => $settings->name))->setTo(array($recepient->email => $recepient->name));
                 try {
                     $response = $mailer->send($message);
                 } catch (\Exception $e) {
                     //todo: log error
                 }
             } else {
                 if ($recepient->phone_number && $settings->twilio_sid && $settings->twilio_token && $settings->twilio_phonenumber) {
                     $message = $client->account->messages->sendMessage($settings->twilio_phonenumber, $recepient->phone_number, $body);
                 }
             }
         }
     }
 }
开发者ID:anchetaWern,项目名称:naughtyfire,代码行数:35,代码来源:Notifier.php

示例7: loadConfig

 /**
  * Parse the configuration file
  *
  * @param array $parsedConfig
  */
 private function loadConfig($parsedConfig)
 {
     if (isset($parsedConfig['moduleConf']['Type']) && $parsedConfig['moduleConf']['Type'] == "smtp") {
         $this->transport = \Swift_SmtpTransport::newInstance();
         if (isset($parsedConfig['moduleConf']['Host']) && $parsedConfig['moduleConf']['Host'] != "") {
             $this->transport->setHost($parsedConfig['moduleConf']['Host']);
         }
         if (isset($parsedConfig['moduleConf']['Port']) && $parsedConfig['moduleConf']['Port'] != "") {
             $this->transport->setPort($parsedConfig['moduleConf']['Port']);
         }
         if (isset($parsedConfig['moduleConf']['Username']) && $parsedConfig['moduleConf']['Username'] != "") {
             $this->transport->setUsername($parsedConfig['moduleConf']['Username']);
         }
         if (isset($parsedConfig['moduleConf']['Password']) && $parsedConfig['moduleConf']['Password'] != "") {
             $this->transport->setPassword($parsedConfig['moduleConf']['Password']);
         }
         if (isset($parsedConfig['moduleConf']['Encryption']) && $parsedConfig['moduleConf']['Encryption'] != "") {
             $this->transport->setEncryption($parsedConfig['moduleConf']['Encryption']);
         }
     } elseif (isset($parsedConfig['moduleConf']['Type']) && $parsedConfig['moduleConf']['Type'] == "sendmail") {
         $this->transport = \Swift_SendmailTransport::newInstance('/usr/sbin/sendmail -bs');
     } else {
         $this->transport = \Swift_MailTransport::newInstance();
     }
 }
开发者ID:stonedz,项目名称:pff2,代码行数:30,代码来源:Mail.php

示例8: send

 /**
  * Send a mail
  *
  * @param string $subject
  * @param string $content
  * @return bool|string false is everything was fine, or error string
  */
 public function send($subject, $content)
 {
     try {
         // Test with custom SMTP connection
         if ($this->smtp_checked) {
             // Retrocompatibility
             if (Tools::strtolower($this->encryption) === 'off') {
                 $this->encryption = false;
             }
             $smtp = Swift_SmtpTransport::newInstance($this->server, $this->port, $this->encryption);
             $smtp->setUsername($this->login);
             $smtp->setpassword($this->password);
             $smtp->setTimeout(5);
             $swift = Swift_Mailer::newInstance($smtp);
         } else {
             // Test with normal PHP mail() call
             $swift = Swift_Mailer::newInstance(Swift_MailTransport::newInstance());
         }
         $message = Swift_Message::newInstance();
         $message->setFrom($this->email)->setTo('no-reply@' . Tools::getHttpHost(false, false, true))->setSubject($subject)->setBody($content);
         $message = new Swift_Message($subject, $content, 'text/html');
         if (@$swift->send($message)) {
             $result = true;
         } else {
             $result = 'Could not send message';
         }
         $swift->disconnect();
     } catch (Swift_SwiftException $e) {
         $result = $e->getMessage();
     }
     return $result;
 }
开发者ID:prestanesia,项目名称:PrestaShop,代码行数:39,代码来源:mail.php

示例9: initialize

 public function initialize()
 {
     require_once TD_INC . 'swift/swift_required.php';
     if ($this->config['transport'] == 'smtp') {
         $this->transport = Swift_SmtpTransport::newInstance($this->config['smtp_host']);
         if ($this->config['smtp_port']) {
             $this->transport->setPort($this->config['smtp_port']);
         }
         if ($this->config['smtp_encryption']) {
             $this->transport->setEncryption($this->config['smtp_encryption']);
         }
         if ($this->config['smtp_user']) {
             $this->transport->setUsername($this->config['smtp_user']);
         }
         if ($this->config['smtp_pass']) {
             $this->transport->setPassword($this->config['smtp_pass']);
         }
         if ($this->config['smtp_timeout']) {
             $this->transport->setTimeout($this->config['smtp_timeout']);
         }
     } elseif ($this->config['transport'] == 'sendmail') {
         $this->transport = Swift_SendmailTransport::newInstance();
         if ($this->config['sendmail_command']) {
             $this->transport->setCommand($this->config['sendmail_command']);
         }
     } elseif ($this->config['transport'] == 'mail') {
         $this->transport = Swift_MailTransport::newInstance();
     }
     $this->mailer = Swift_Mailer::newInstance($this->transport);
 }
开发者ID:purna89,项目名称:TrellisDesk,代码行数:30,代码来源:class_email.php

示例10: __construct

 public function __construct(LiveCart $application)
 {
     $this->application = $application;
     $this->set('request', $application->getRequest()->toArray());
     $this->url = $this->application->router->createFullUrl('/', null, true);
     $config = $this->application->getConfig();
     ClassLoader::ignoreMissingClasses();
     if ('SMTP' == $config->get('EMAIL_METHOD')) {
         $server = $config->get('SMTP_SERVER');
         if (!$server) {
             $server = ini_get('SMTP');
         }
         $this->connection = Swift_SmtpTransport::newInstance($server, $config->get('SMTP_PORT'));
         if ($config->get('SMTP_USERNAME')) {
             $this->connection->setUsername($config->get('SMTP_USERNAME'));
             $this->connection->setPassword($config->get('SMTP_PASSWORD'));
         }
     } else {
         if ('FAKE' == $config->get('EMAIL_METHOD')) {
             $this->connection = Swift_Connection_Fake::newInstance();
         } else {
             $this->connection = Swift_MailTransport::newInstance();
         }
     }
     $this->swiftInstance = Swift_Mailer::newInstance($this->connection);
     $this->message = Swift_Message::newInstance();
     $this->setFrom($config->get('MAIN_EMAIL'), $config->get('STORE_NAME'));
     ClassLoader::ignoreMissingClasses(false);
 }
开发者ID:saiber,项目名称:www,代码行数:29,代码来源:Email.php

示例11: indexAction

 public function indexAction()
 {
     if ($this->request->isPost() == true) {
         require_once PUBLIC_PATH . 'library/swiftmailer/lib/swift_required.php';
         //Settings
         $mail_settings = $this->config->mail;
         // Create the SMTP configuration
         $transport = \Swift_SmtpTransport::newInstance($mail_settings->smtp->server, $mail_settings->smtp->port, $mail_settings->smtp->security);
         $transport->setUsername($mail_settings->smtp->username);
         $transport->setPassword($mail_settings->smtp->password);
         $form_data = $this->request->getPost();
         // Create the message
         $message = \Swift_Message::newInstance();
         $message->setTo(array($form_data['fromEmail']));
         $message->setSubject($form_data['title']);
         $message->setBody($form_data['content']);
         $message->setFrom($mail_settings->from_email, $mail_settings->from_name);
         // Send the email
         $mailer = \Swift_Mailer::newInstance($transport);
         $result = $mailer->send($message);
         if ($result) {
             $this->flash->success("Thank you, sent mail successful!");
             $tbl_contact = new \Modules\Frontend\Models\Contact();
             $tbl_contact->fullname = $form_data['fullName'];
             $tbl_contact->from_mail = $form_data['fromEmail'];
             $tbl_contact->title = $form_data['title'];
             $tbl_contact->content = $form_data['content'];
             $tbl_contact->status = '0';
             $tbl_contact->send_date = date('Y-m-d H:i:s');
             $tbl_contact->save();
         } else {
             $this->flash->error("Failed! Please send mail again!");
         }
     }
 }
开发者ID:quyquoc,项目名称:rmt-studio.com,代码行数:35,代码来源:ContactController.php

示例12: send

 public function send($lastOverride = false)
 {
     $i18n = Localization::getTranslator();
     $lastFn = '/home/pi/phplog/last-tx-sent';
     $last = 0;
     if (file_exists($lastFn)) {
         $last = intval(trim(file_get_contents($lastFn)));
     }
     if ($lastOverride !== false) {
         $last = $lastOverride;
     }
     $csvMaker = Container::dispense('TransactionCSV');
     $config = Admin::volatileLoad()->getConfig();
     $transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, 'ssl')->setUsername($config->getEmailUsername())->setPassword($config->getEmailPassword());
     $msg = Swift_Message::newInstance()->setSubject($config->getMachineName() . $i18n->_(': Transaction Log'))->setFrom([$config->getEmailUsername() => $config->getMachineName()])->setTo(array($config->getEmailUsername()))->setBody($i18n->_('See attached for transaction log.'));
     $file = $csvMaker->save($last);
     if (!$file) {
         throw new Exception('Unable to save CSV');
     }
     $msg->attach(Swift_Attachment::fromPath($file));
     file_put_contents($lastFn, $csvMaker->getLastID());
     $mailer = Swift_Mailer::newInstance($transport);
     if (!$mailer->send($msg)) {
         throw new Exception('Unable to send: unkown cause');
     }
 }
开发者ID:oktoshi,项目名称:skyhook,代码行数:26,代码来源:CSVMailer.php

示例13: getMailer

 protected function getMailer()
 {
     if (empty($this->mailer)) {
         require_once PATH_SYSTEM . "/vendors/Swift-4.0.4/lib/swift_required.php";
         switch ($this->emailMode) {
             case 'smtp':
                 //Create the Transport
                 $transport = Swift_SmtpTransport::newInstance($this->emailConfig['host'], $this->emailConfig['port']);
                 if (!empty($this->emailConfig['user'])) {
                     $transport->setUsername($this->emailConfig['user']);
                 }
                 if (!empty($this->emailConfig['password'])) {
                     $transport->setPassword($this->emailConfig['password']);
                 }
                 if (!empty($this->emailConfig['timeout'])) {
                     $transport->setTimeout($this->emailConfig['timeout']);
                 }
                 if (!empty($this->emailConfig['encryption'])) {
                     $transport->setEncryption($this->emailConfig['encryption']);
                 }
                 $this->mailer = Swift_Mailer::newInstance($transport);
                 break;
             case 'sendmail':
                 $transport = Swift_SendmailTransport::newInstance(!empty($this->emailConfig['pathToSendmail']) ? $this->emailConfig['pathToSendmail'] : '/usr/sbin/sendmail -bs');
                 $this->mailer = Swift_Mailer::newInstance($transport);
                 break;
             default:
             case 'mail':
                 $transport = Swift_MailTransport::newInstance();
                 $this->mailer = Swift_Mailer::newInstance($transport);
                 break;
         }
     }
     return $this->mailer;
 }
开发者ID:wb-crowdfusion,项目名称:crowdfusion,代码行数:35,代码来源:Email.php

示例14: send

 /**
  * @param $to
  * @param $subject
  * @param $body
  * @return bool
  */
 public function send($to, $subject, $body)
 {
     include_once "vendor/autoload.php";
     date_default_timezone_set("Asia/Colombo");
     $this->CI->config->load('send_grid');
     $username = $this->CI->config->item('send_grid_username');
     $password = $this->CI->config->item('send_grid_password');
     $smtp_server = $this->CI->config->item('send_grid_smtp_server');
     $smtp_server_port = $this->CI->config->item('send_grid_smtp_server_port');
     $sending_address = $this->CI->config->item('email_sender_address');
     $sending_name = $this->CI->config->item('email_sender_name');
     $from = array($sending_address => $sending_name);
     $to = array($to);
     $transport = Swift_SmtpTransport::newInstance($smtp_server, $smtp_server_port);
     $transport->setUsername($username);
     $transport->setPassword($password);
     $swift = Swift_Mailer::newInstance($transport);
     $message = new Swift_Message($subject);
     $message->setFrom($from);
     $message->setBody($body, 'text/html');
     $message->setTo($to);
     $message->addPart($body, 'text/plain');
     // send message
     if ($recipients = $swift->send($message, $failures)) {
         return true;
     } else {
         return false;
     }
 }
开发者ID:sandeepa91,项目名称:JMS-V1,代码行数:35,代码来源:EmailSender.php

示例15: EnviarCorreoConfirmacionTransaccion

 public function EnviarCorreoConfirmacionTransaccion($nombre, $email, $id_transaccion)
 {
     //echo "Enviando Correos";
     //ini_set('max_execution_time', 28800); //240 segundos = 4 minutos
     //Enviar correo electr�nico
     $url = base_url();
     $transport = Swift_SmtpTransport::newInstance()->setHost('smtp.gmail.com')->setPort(465)->setEncryption('ssl')->setUsername('agencia@gmail.com')->setPassword('passsword');
     //Create the Mailer using your created Transport
     $mailer = Swift_Mailer::newInstance($transport);
     //$this->load->model("Solicitud_model", "solicitud");
     //$query = $this->solicitud->getAlumnosCorreo();
     //Pass it as a parameter when you create the message
     $message = Swift_Message::newInstance();
     //Give the message a subject
     //Or set it after like this
     $message->setSubject('Confirmacion Transaccion Agencia');
     //no_reply@ugto.mx
     $message->setFrom(array('agencia@gmail.com' => 'Agencia'));
     $message->addTo($email);
     //$message->addTo('mgsnikips@gmail.com');
     //$message->addBcc('fabishodev@gmail.com');
     //Add alternative parts with addPart()
     $failedRecipients = array();
     $message->addPart("<h2>Gracias por su preferencia, </h2>" . $nombre . "\n                <br>\n                <h3>Su transaccion ha sido realizada con éxito.</h3>\n                <br>\n                No. Transaccion: " . $id_transaccion . "<br>\n                ---<br>\n                ", 'text/html');
     if (!$mailer->send($message)) {
         return FALSE;
     }
     return TRUE;
 }
开发者ID:fabishodev,项目名称:agencia,代码行数:29,代码来源:Mensaje.php


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