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


PHP Swift::disconnect方法代码示例

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


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

示例1: executePassword

 public function executePassword()
 {
     $this->form = new RequestPasswordForm();
     if ($this->getRequest()->isMethod('get')) {
         return;
     }
     $this->form->bind($this->getRequest()->getParameter('form'));
     if (!$this->form->isValid()) {
         return;
     }
     $email = $this->form->getValue('email');
     $password = substr(md5(rand(100000, 999999)), 0, 6);
     $sfGuardUserProfile = sfGuardUserProfilePeer::retrieveByEmail($email);
     $sfGuardUser = $sfGuardUserProfile->getSfGuardUser();
     $sfGuardUser->setPassword($password);
     try {
         $connection = new Swift_Connection_SMTP('mail.sis-nav.com', 25);
         $connection->setUsername('umut.utkan@sistemas.com.tr');
         $connection->setPassword('gahve123');
         $mailer = new Swift($connection);
         $message = new Swift_Message('Request Password');
         $mailContext = array('email' => $email, 'password' => $password, 'username' => $sfGuardUser->getUsername(), 'full_name' => $sfGuardUserProfile->getFirstName());
         $message->attach(new Swift_Message_Part($this->getPartial('mail/requestPasswordHtmlBody', $mailContext), 'text/html'));
         $message->attach(new Swift_Message_Part($this->getPartial('mail/requestPasswordTextBody', $mailContext), 'text/plain'));
         $mailer->send($message, $email, 'admin@project-y.com');
         $mailer->disconnect();
     } catch (Exception $e) {
         $mailer->disconnect();
     }
     $sfGuardUser->save();
     $this->getUser()->setFlash('info', 'A new password is sent to your email.');
     $this->forward('site', 'message');
 }
开发者ID:hoydaa,项目名称:googlevolume.com,代码行数:33,代码来源:actions.class.php

示例2: send

 /**
  * Send a contact mail (text only) with the data provided by the given form.
  *
  * @uses Swift
  *
  * @throws InvalidArgumentException
  * @throws RuntimeException
  *
  * @param sfContactForm $form A valid contact form which contains the content.
  * @param sfContactFormDecorator $decorator Defaults to null. If given, the decorated subject and message will be used.
  *
  * @return bool True if all recipients got the mail.
  */
 public static function send(sfContactForm $form, sfContactFormDecorator $decorator = null)
 {
     if (!$form->isValid()) {
         throw new InvalidArgumentException('The given form is not valid.', 1);
     }
     if (!class_exists('Swift')) {
         throw new RuntimeException('Swift could not be found.');
     }
     // set up sender
     $from = sfConfig::get('sf_contactformplugin_from', false);
     if ($from === false) {
         throw new InvalidArgumentException('Configuration value of sf_contactformplugin_from is missing.', 2);
     }
     // where to send the contents of the contact form
     $mail = sfConfig::get('sf_contactformplugin_mail', false);
     if ($mail === false) {
         throw new InvalidArgumentException('Configuration value of sf_contactformplugin_mail is missing.', 3);
     }
     // set up mail content
     if (!is_null($decorator)) {
         $subject = $decorator->getSubject();
         $body = $decorator->getMessage();
     } else {
         $subject = $form->getValue('subject');
         $body = $form->getValue('message');
     }
     // set up recipients
     $recipients = new Swift_RecipientList();
     // check amount for given recipients
     $recipientCheck = 0;
     // use the sender as recipient to apply other recipients only as blind carbon copy
     $recipients->addTo($from);
     $recipientCheck++;
     // add a mail where to send the message
     $recipients->addBcc($mail);
     $recipientCheck++;
     // add sender to recipients, if chosen
     if ($form->getValue('sendcopy')) {
         $recipients->addBcc($form->getValue('email'));
         $recipientCheck++;
     }
     if (count($recipients->getIterator('bcc')) === 0) {
         throw new InvalidArgumentException('There are no recipients given.', 4);
     }
     // send the mail using swift
     try {
         $mailer = new Swift(new Swift_Connection_NativeMail());
         $message = new Swift_Message($subject, $body, 'text/plain');
         $countRecipients = $mailer->send($message, $recipients, $from);
         $mailer->disconnect();
         return $countRecipients == $recipientCheck;
     } catch (Exception $e) {
         $mailer->disconnect();
         throw $e;
     }
 }
开发者ID:havvg,项目名称:sfContactFormPlugin,代码行数:69,代码来源:sfContactFormMail.class.php

示例3: sendMail

 public static function sendMail($smtpChecked, $smtpServer, $content, $subject, $type, $to, $from, $smtpLogin, $smtpPassword, $smtpPort = 25, $smtpEncryption)
 {
     include INSTALL_PATH . '/../tools/swift/Swift.php';
     include INSTALL_PATH . '/../tools/swift/Swift/Connection/SMTP.php';
     include INSTALL_PATH . '/../tools/swift/Swift/Connection/NativeMail.php';
     $swift = NULL;
     $result = NULL;
     try {
         if ($smtpChecked) {
             $smtp = new Swift_Connection_SMTP($smtpServer, $smtpPort, $smtpEncryption == "off" ? Swift_Connection_SMTP::ENC_OFF : ($smtpEncryption == "tls" ? Swift_Connection_SMTP::ENC_TLS : Swift_Connection_SMTP::ENC_SSL));
             $smtp->setUsername($smtpLogin);
             $smtp->setpassword($smtpPassword);
             $smtp->setTimeout(5);
             $swift = new Swift($smtp);
         } else {
             $swift = new Swift(new Swift_Connection_NativeMail());
         }
         $message = new Swift_Message($subject, $content, $type);
         if ($swift->send($message, $to, $from)) {
             $result = true;
         } else {
             $result = 999;
         }
         $swift->disconnect();
     } catch (Swift_Connection_Exception $e) {
         $result = $e->getCode();
     } catch (Swift_Message_MimeException $e) {
         $result = $e->getCode();
     }
     return $result;
 }
开发者ID:sealence,项目名称:local,代码行数:31,代码来源:ToolsInstall.php

示例4: 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) {
             $smtp = new Swift_Connection_SMTP($this->server, $this->port, $this->encryption == "off" ? Swift_Connection_SMTP::ENC_OFF : ($this->encryption == "tls" ? Swift_Connection_SMTP::ENC_TLS : Swift_Connection_SMTP::ENC_SSL));
             $smtp->setUsername($this->login);
             $smtp->setpassword($this->password);
             $smtp->setTimeout(5);
             $swift = new Swift($smtp);
         } else {
             // Test with normal PHP mail() call
             $swift = new Swift(new Swift_Connection_NativeMail());
         }
         $message = new Swift_Message($subject, $content, 'text/html');
         if (@$swift->send($message, $this->email, 'no-reply@' . Tools::getHttpHost(false, false, true))) {
             $result = false;
         } else {
             $result = 'Could not send message';
         }
         $swift->disconnect();
     } catch (Swift_Exception $e) {
         $result = $e->getMessage();
     }
     return $result;
 }
开发者ID:sowerr,项目名称:PrestaShop,代码行数:33,代码来源:mail.php

示例5: sendActivationMail

 /**
  * Send an email with an activation link to verify the subscriber is the owner of the email address.
  *
  * @throws InvalidArgumentException
  * @throws Exception
  *
  * @return bool
  */
 protected function sendActivationMail(Subscriber $subscriber)
 {
     try {
         $from = sfNewsletterPluginConfiguration::getFromEmail();
         $mailer = new Swift(new Swift_Connection_NativeMail());
         $message = new Swift_Message(sfConfig::get('sf_newsletter_plugin_activation_mail_subject', 'Newsletter Subscription'), $this->getPartial('activation_mail', array('subscriber' => $subscriber)), 'text/html');
         $sent = $mailer->send($message, $subscriber->getEmail(), $from);
         $mailer->disconnect();
         return $sent === 1;
     } catch (Exception $e) {
         if (!empty($mailer)) {
             $mailer->disconnect();
         }
         throw $e;
     }
 }
开发者ID:havvg,项目名称:sfNewsletterPlugin,代码行数:24,代码来源:subscribeAction.class.php

示例6: send

 public function send()
 {
     //load swift class.
     require_once CLASSES_DIR . "Swift.php";
     Swift_ClassLoader::load("Swift_Connection_SMTP");
     // Create the message, and set the message subject.
     $message =& new Swift_Message($this->get('subject'));
     //create the html / text body
     $message->attach(new Swift_Message_Part($this->get('html_body'), "text/html"));
     $message->attach(new Swift_Message_Part($this->get('text_body'), "text/plain"));
     // Set the from address/name.
     $from =& new Swift_Address(EMAIL_USERNAME, EMAIL_NAME);
     // Create the recipient list.
     $recipients =& new Swift_RecipientList();
     // Add the recipient
     $recipients->addTo($this->get('to_email'), $this->get('to_name'));
     //connect and create mailer
     $smtp =& new Swift_Connection_SMTP("smtp.gmail.com", Swift_Connection_SMTP::PORT_SECURE, Swift_Connection_SMTP::ENC_TLS);
     $smtp->setUsername(EMAIL_USERNAME);
     $smtp->setPassword(EMAIL_PASSWORD);
     $mailer = new Swift($smtp);
     // Attempt to send the email.
     try {
         $result = $mailer->send($message, $recipients, $from);
         $mailer->disconnect();
         $this->set('status', 'sent');
         $this->set('sent_date', date("Y-m-d H:i:s"));
         $this->save();
         return true;
     } catch (Swift_BadResponseException $e) {
         return $e->getMessage();
     }
 }
开发者ID:ricberw,项目名称:BotQueue,代码行数:33,代码来源:email.php

示例7: isAuthenticated

 /**
  * Try to authenticate using the username and password
  * Returns false on failure
  * @param string The username
  * @param string The password
  * @param Swift The instance of Swift this authenticator is used in
  * @return boolean
  */
 public function isAuthenticated($user, $pass, Swift $swift)
 {
   $log = Swift_LogContainer::getLog();
   if ($log->hasLevel(Swift_Log::LOG_EVERYTHING))
   {
     $log->add("Trying POP3 Before SMTP authentication.  Disconnecting from SMTP first.");
   }
   $swift->disconnect();
   try {
     $this->connection->start();
     $this->connection->assertOk($this->connection->read());
     $this->connection->write("USER " . $user);
     $this->connection->assertOk($this->connection->read());
     $this->connection->write("PASS " . $pass);
     $this->connection->assertOk($this->connection->read());
     $this->connection->write("QUIT");
     $this->connection->assertOk($this->connection->read());
     $this->connection->stop();
   } catch (Swift_ConnectionException $e) {
     if ($log->hasLevel(Swift_Log::LOG_ERRORS))
     {
       $log->add($e->getMessage(),Swift_Log::ERROR);
       $log->add("POP3 authentication failed.");
     }
     return false;
   }
   $options = $swift->getOptions();
   $swift->setOptions($options | Swift::NO_POST_CONNECT);
   $swift->connect();
   $swift->setOptions($options);
   return true;
 }
开发者ID:neutrinog,项目名称:Door43,代码行数:40,代码来源:PopB4Smtp.php

示例8: sendEmail

 static function sendEmail($params)
 {
     $mailTo = $params['to'];
     $mailFrom = $params['from'];
     try {
         // Create the Mail Object
         $mailer = new Swift(new Swift_Connection_NativeMail());
         $message = new Swift_Message($params['subject'], $params['body'], 'text/html');
         // Send
         $mailer->send($message, $mailTo, $mailFrom);
         $mailer->disconnect();
         // echo 'Email Sent';
     } catch (Exception $e) {
         $mailer->disconnect();
         echo 'Error: ' . $e;
     }
 }
开发者ID:bshaffer,项目名称:Donate-Nashville,代码行数:17,代码来源:EmailHelper.class.php

示例9: disconnect

 /**
  * Disconnect mailer
  *
  * @param void
  * @return boolean
  */
 function disconnect()
 {
     if ($this->connected && instance_of($this->swift, 'Swift')) {
         $this->swift->disconnect();
     }
     // if
     $this->connected = false;
 }
开发者ID:NaszvadiG,项目名称:activecollab_loc,代码行数:14,代码来源:ApplicationMailer.class.php

示例10: forceRestartSwift

 /**
  * Restarts Swift forcibly.
  */
 protected function forceRestartSwift()
 {
     //Pre-empting problems trying to issue "QUIT" to a dead connection
     $this->swift->connection->stop();
     $this->swift->connection->start();
     $this->swift->disconnect();
     //Restart swift
     $this->swift->connect();
 }
开发者ID:AlexanderS,项目名称:Part-DB,代码行数:12,代码来源:BatchMailer.php

示例11: execute

 /**
  * Send scheduled newsletters to all active subscribers.
  *
  * @todo Add event listener to swift in order to try resending the newsletter.
  *
  * @throws InvalidArgumentException
  *
  * @param array $arguments
  * @param array $options
  *
  * @return void
  */
 protected function execute($arguments = array(), $options = array())
 {
     // initialize the database connection
     $databaseManager = new sfDatabaseManager($this->configuration);
     $connection = $databaseManager->getDatabase($options['connection'] ? $options['connection'] : null)->getConnection();
     try {
         $from = sfNewsletterPluginConfiguration::getFromEmail();
     } catch (InvalidArgumentException $e) {
         $this->logSection($this->name, $e->getMessage(), 30, 'ERROR');
         throw $e;
     }
     $newsletters = NewsletterPeer::retrieveScheduled(new DateTime($options['schedule']));
     if (empty($newsletters)) {
         $this->logSection($this->name, 'There are no newsletters on schedule.');
         return;
     }
     /* @var $eachNewsletter Newsletter */
     foreach ($newsletters as $eachNewsletter) {
         try {
             // get recipient list
             $recipientList = NewsletterRecipientList::createInstanceActiveSubscribers();
             $recipientList->addTo($from);
             // send the mail using swift
             try {
                 $mailer = new Swift(new Swift_Connection_NativeMail());
                 $message = new Swift_Message($eachNewsletter->getSubject(), $eachNewsletter->getContent(), $eachNewsletter->getContentType()->getMimeType());
                 $sent = $mailer->send($message, $recipientList, $from);
                 $mailer->disconnect();
                 if ($sent < count($recipientList)) {
                     $this->logSection($this->name, sprintf(sfNewsletterPluginConfiguration::EXCEPTION_SWIFT_ERROR . ' Error: Email has not reached all recipients. Successfully sent to %d of %d recipients.', $sent, count($recipientList)), null, 'ERROR');
                 }
             } catch (Exception $e) {
                 $mailer->disconnect();
                 $this->logSection($this->name, sfNewsletterPluginConfiguration::EXCEPTION_SWIFT_ERROR . ' Error: ' . $e->getMessage(), null, 'ERROR');
                 throw $e;
             }
         } catch (RuntimeException $e) {
             $this->logSection($this->name, $e->getMessage());
             throw $e;
         }
     }
 }
开发者ID:havvg,项目名称:sfNewsletterPlugin,代码行数:54,代码来源:SendScheduledNewsletterTask.class.php

示例12: forceRestartSwift

 /**
  * Restarts Swift forcibly.
  */
 function forceRestartSwift()
 {
     Swift_Errors::reset();
     //Pre-empting problems trying to issue "QUIT" to a dead connection
     $this->swift->connection->stop();
     $this->swift->connection->start();
     $this->swift->disconnect();
     //Restart swift
     $this->swift->connect();
     $this->doRestart = false;
 }
开发者ID:NaszvadiG,项目名称:activecollab_loc,代码行数:14,代码来源:BatchMailer.php

示例13: executeSignUp

 public function executeSignUp($request)
 {
     $this->form = new SignUpForm();
     if ($request->isMethod('get')) {
         return;
     }
     $this->form->bind($request->getParameter('form'));
     if (!$this->form->isValid()) {
         return;
     }
     $sfGuardUser = new sfGuardUser();
     $sfGuardUser->setUsername($this->form->getValue('username'));
     $sfGuardUser->setPassword($this->form->getValue('password'));
     $sfGuardUser->setIsActive(false);
     $sfGuardUser->save();
     $sfGuardUserProfile = new sfGuardUserProfile();
     $sfGuardUserProfile->setSfGuardUser($sfGuardUser);
     $sfGuardUserProfile->setEmail($this->form->getValue('email'));
     $sfGuardUserProfile->setFirstName($this->form->getValue('first_name'));
     $sfGuardUserProfile->setLastName($this->form->getValue('last_name'));
     $sfGuardUserProfile->setGender($this->form->getValue('gender'));
     $sfGuardUserProfile->setBirthday($this->form->getValue('birthday'));
     $sfGuardUserProfile->setWebpage($this->form->getValue('webpage'));
     $sfGuardUserProfile->save();
     try {
         $connection = new Swift_Connection_SMTP('mail.sis-nav.com', 25);
         $connection->setUsername('umut.utkan@sistemas.com.tr');
         $connection->setPassword('gahve123');
         $mailer = new Swift($connection);
         $message = new Swift_Message('Account Confirmation');
         $mailContext = array('email' => $sfGuardUserProfile->getEmail(), 'full_name' => $sfGuardUserProfile->getFullName(), 'activation_key' => $sfGuardUserProfile->getActivationKey());
         $message->attach(new Swift_Message_Part($this->getPartial('mail/signUpHtmlBody', $mailContext), 'text/html'));
         $message->attach(new Swift_Message_Part($this->getPartial('mail/signUpTextBody', $mailContext), 'text/plain'));
         $mailer->send($message, $sfGuardUserProfile->getEmail(), 'admin@project-y.com');
         $mailer->disconnect();
     } catch (Exception $e) {
         $mailer->disconnect();
     }
     $this->getUser()->setFlash('info', 'A confirmation email has been sent to your email address.');
     $this->forward('site', 'message');
 }
开发者ID:hoydaa,项目名称:googlevolume.com,代码行数:41,代码来源:actions.class.php

示例14: close

 /**
  * Close the connection to the MTA
  * @return boolean
  */
 public function close()
 {
     if ($this->isConnected()) {
         try {
             $this->swift->disconnect();
             return true;
         } catch (Swift_ConnectionException $e) {
             $this->setError("Disconnect failed:<br />" . $e->getMessage());
         }
     }
     return false;
 }
开发者ID:darkcolonist,项目名称:kohana234-doctrine115,代码行数:16,代码来源:EasySwift.php

示例15: close

 /**
  * Close the connection to the MTA
  * @return boolean
  */
 function close()
 {
     if ($this->isConnected()) {
         Swift_Errors::expect($e, "Swift_ConnectionException");
         $this->swift->disconnect();
         if ($e) {
             $this->setError("Disconnect failed:<br />" . $e->getMessage());
             return false;
         }
         Swift_Errors::clear("Swift_ConnectionException");
     }
     return true;
 }
开发者ID:jeffthestampede,项目名称:excelsior,代码行数:17,代码来源:EasySwift.php


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