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


PHP POP3::authorize方法代码示例

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


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

示例1: _sendEmail

 /**
  * @param UserModel  $user
  * @param EmailModel $emailModel
  * @param array      $variables
  *
  * @throws Exception
  * @return bool
  */
 private function _sendEmail(UserModel $user, EmailModel $emailModel, $variables = array())
 {
     // Get the saved email settings.
     $emailSettings = $this->getSettings();
     if (!isset($emailSettings['protocol'])) {
         throw new Exception(Craft::t('Could not determine how to send the email.  Check your email settings.'));
     }
     // Fire an 'onBeforeSendEmail' event
     $event = new Event($this, array('user' => $user, 'emailModel' => $emailModel, 'variables' => $variables));
     $this->onBeforeSendEmail($event);
     // Is the event giving us the go-ahead?
     if ($event->performAction) {
         // In case a plugin changed any variables in onBeforeSendEmail
         $variables = $event->params['variables'];
         $email = new \PHPMailer(true);
         // Default the charset to UTF-8
         $email->CharSet = 'UTF-8';
         // Add a reply to (if any).  Make sure it’s set before setting From, because email is dumb.
         if (!empty($emailModel->replyTo)) {
             $email->addReplyTo($emailModel->replyTo);
         }
         // Set the "from" information.
         $email->setFrom($emailModel->fromEmail, $emailModel->fromName);
         // Check which protocol we need to use.
         switch ($emailSettings['protocol']) {
             case EmailerType::Gmail:
             case EmailerType::Smtp:
                 $this->_setSmtpSettings($email, $emailSettings);
                 break;
             case EmailerType::Pop:
                 $pop = new \POP3();
                 if (!isset($emailSettings['host']) || !isset($emailSettings['port']) || !isset($emailSettings['username']) || !isset($emailSettings['password']) || StringHelper::isNullOrEmpty($emailSettings['host']) || StringHelper::isNullOrEmpty($emailSettings['port']) || StringHelper::isNullOrEmpty($emailSettings['username']) || StringHelper::isNullOrEmpty($emailSettings['password'])) {
                     throw new Exception(Craft::t('Host, port, username and password must be configured under your email settings.'));
                 }
                 if (!isset($emailSettings['timeout'])) {
                     $emailSettings['timeout'] = $this->_defaultEmailTimeout;
                 }
                 $pop->authorize($emailSettings['host'], $emailSettings['port'], $emailSettings['timeout'], $emailSettings['username'], $emailSettings['password'], craft()->config->get('devMode') ? 1 : 0);
                 $this->_setSmtpSettings($email, $emailSettings);
                 break;
             case EmailerType::Sendmail:
                 $email->isSendmail();
                 break;
             case EmailerType::Php:
                 $email->isMail();
                 break;
             default:
                 $email->isMail();
         }
         if (!$this->_processTestToEmail($email, 'Address')) {
             $email->addAddress($user->email, $user->getFullName());
         }
         // Add any custom headers
         if (!empty($emailModel->customHeaders)) {
             foreach ($emailModel->customHeaders as $headerName => $headerValue) {
                 $email->addCustomHeader($headerName, $headerValue);
             }
         }
         // Add any BCC's
         if (!empty($emailModel->bcc)) {
             if (!$this->_processTestToEmail($email, 'BCC')) {
                 foreach ($emailModel->bcc as $bcc) {
                     if (!empty($bcc['email'])) {
                         $bccEmail = $bcc['email'];
                         $bccName = !empty($bcc['name']) ? $bcc['name'] : '';
                         $email->addBCC($bccEmail, $bccName);
                     }
                 }
             }
         }
         // Add any CC's
         if (!empty($emailModel->cc)) {
             if (!$this->_processTestToEmail($email, 'CC')) {
                 foreach ($emailModel->cc as $cc) {
                     if (!empty($cc['email'])) {
                         $ccEmail = $cc['email'];
                         $ccName = !empty($cc['name']) ? $cc['name'] : '';
                         $email->addCC($ccEmail, $ccName);
                     }
                 }
             }
         }
         // Add a sender header (if any)
         if (!empty($emailModel->sender)) {
             $email->Sender = $emailModel->sender;
         }
         // Add any string attachments
         if (!empty($emailModel->stringAttachments)) {
             foreach ($emailModel->stringAttachments as $stringAttachment) {
                 $email->addStringAttachment($stringAttachment['string'], $stringAttachment['fileName'], $stringAttachment['encoding'], $stringAttachment['type']);
             }
         }
//.........这里部分代码省略.........
开发者ID:reedmaniac,项目名称:reedmaniac,代码行数:101,代码来源:EmailService.php


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