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


PHP CakeEmail::addBcc方法代码示例

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


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

示例1: sendMail

 /**
  * メールを送信する
  *
  * @param string $to 送信先アドレス
  * @param string $title タイトル
  * @param mixed $body 本文
  * @param array $options オプション
  * @return bool 送信結果
  */
 public function sendMail($to, $title = '', $body = '', $options = array())
 {
     $options = array_merge(array('agentTemplate' => true, 'template' => 'default'), $options);
     if (!empty($this->siteConfigs['smtp_host'])) {
         $transport = 'Smtp';
         $host = $this->siteConfigs['smtp_host'];
         $port = $this->siteConfigs['smtp_port'] ? $this->siteConfigs['smtp_port'] : 25;
         $username = $this->siteConfigs['smtp_user'] ? $this->siteConfigs['smtp_user'] : null;
         $password = $this->siteConfigs['smtp_password'] ? $this->siteConfigs['smtp_password'] : null;
         $tls = $this->siteConfigs['smtp_tls'] && $this->siteConfigs['smtp_tls'] == 1;
     } else {
         $transport = 'Mail';
         $host = 'localhost';
         $port = 25;
         $username = null;
         $password = null;
         $tls = null;
     }
     $config = array('transport' => $transport, 'host' => $host, 'port' => $port, 'username' => $username, 'password' => $password, 'tls' => $tls);
     $cakeEmail = new CakeEmail($config);
     // charset
     if (!empty($this->siteConfigs['mail_encode'])) {
         $encode = $this->siteConfigs['mail_encode'];
     } else {
         $encode = 'ISO-2022-JP';
     }
     // ISO-2022-JPの場合半角カナが文字化けしてしまうので全角に変換する
     if ($encode == 'ISO-2022-JP') {
         $title = mb_convert_kana($title, 'KV', "UTF-8");
         if (is_string($body)) {
             $body = mb_convert_kana($body, 'KV', "UTF-8");
         } elseif (isset($body['message']) && is_array($body['message'])) {
             foreach ($body['message'] as $key => $val) {
                 if (is_string($val)) {
                     $body['message'][$key] = mb_convert_kana($val, 'KV', "UTF-8");
                 }
             }
         }
     }
     //CakeEmailの内部処理のencodeを統一したいので先に値を渡しておく
     $cakeEmail->headerCharset($encode);
     $cakeEmail->charset($encode);
     //$format
     if (!empty($options['format'])) {
         $cakeEmail->emailFormat($options['format']);
     } else {
         $cakeEmail->emailFormat('text');
     }
     //bcc 'mail@example.com,mail2@example.com'
     if (!empty($options['bcc'])) {
         // 文字列の場合
         $bcc = array();
         if (is_string($options['bcc'])) {
             if (strpos($options['bcc'], ',') !== false) {
                 $bcc = explode(',', $options['bcc']);
             } else {
                 $bcc[] = $options['bcc'];
             }
             // 配列の場合
         } elseif (is_array($options['bcc'])) {
             $bcc = $options['bcc'];
         }
         foreach ($bcc as $val) {
             if (Validation::email(trim($val))) {
                 $cakeEmail->addBcc($val);
             }
         }
         unset($bcc);
     }
     //cc 'mail@example.com,mail2@example.com'
     if (!empty($options['cc'])) {
         // 文字列の場合
         $cc = array();
         if (is_string($options['cc'])) {
             if (strpos($options['cc'], ',') !== false) {
                 $cc = explode(',', $options['cc']);
             } else {
                 $cc[] = $options['cc'];
             }
             // 配列の場合
         } elseif (is_array($options['cc'])) {
             $cc = $options['cc'];
         }
         foreach ($cc as $val) {
             if (Validation::email(trim($val))) {
                 $cakeEmail->addCc($val);
             }
         }
         unset($cc);
     }
     // to 送信先アドレス (最初の1人がTOで残りがBCC)
//.........这里部分代码省略.........
开发者ID:hanhunhun,项目名称:hanlog,代码行数:101,代码来源:BcAppController.php

示例2: array

 function view_certificate()
 {
     if (empty($this->request->data)) {
         return 'This certificate cannot be generated.';
     } else {
         $is_tutorial = false;
         $is_quiz = false;
         $this->set('tutorial_grades', array());
         $this->set('quiz_grades', array());
         if (array_key_exists('tutorial_id', $this->request->data) && is_numeric($this->request->data['tutorial_id'])) {
             $tutorial = $this->Tutorial->read(null, $this->request->data['tutorial_id']);
             if ($tutorial['Tutorial']['certificate']) {
                 $is_tutorial = true;
                 $subject = $tutorial['Tutorial']['title'];
                 if (!isset($this->request->data['questions'])) {
                     $this->request->data['questions'] = array();
                 }
                 $this->set('tutorial_grades', $this->Tutorial->grade($this->request->data['tutorial_id'], $this->request->data['questions']));
             }
         }
         if (!isset($this->request->data['free-response'])) {
             $this->request->data['free-response'] = array();
         }
         $this->set('free_responses', $this->request->data['free-response']);
         if (array_key_exists('quiz_id', $this->request->data) && is_numeric($this->request->data['quiz_id'])) {
             $final_quiz = $this->Tutorial->FinalQuiz->read(null, $this->request->data['quiz_id']);
             if ($final_quiz['FinalQuiz']['certificate']) {
                 $is_quiz = true;
                 $subject = $final_quiz['Tutorial']['title'];
                 if (!isset($this->request->data['questions'])) {
                     $this->request->data['questions'] = array();
                 }
                 $this->set('quiz_grades', $this->Tutorial->FinalQuiz->grade($this->request->data['quiz_id'], $this->request->data['questions']));
             }
         }
         // parse supplied email fields
         if ($is_tutorial || $is_quiz) {
             $to_string = '';
             if (!empty($tutorial['Tutorial']['certificate_email'])) {
                 $to_string .= $tutorial['Tutorial']['certificate_email'];
             }
             if (!empty($this->request->data['certificate_email'])) {
                 if (!empty($to_string)) {
                     $to_string .= ',';
                 }
                 $to_string .= $this->request->data['certificate_email'];
             }
             $this->set('date', date('F j, Y'));
             $this->set('time', date('g:ia'));
             $this->set('name', Sanitize::paranoid($this->request->data['certificate_name'], array(' ')));
             $this->set('title', $subject);
             $message = new CakeEmail('default');
             $message->subject("Certificate of Completion for {$subject}");
             $message->template('certificate_of_completion');
             $message->emailFormat('html');
             $message->viewVars($this->viewVars);
             $to_array = explode(',', $to_string);
             foreach ($to_array as $key => $to) {
                 if ($to == 'Emailaddresses' || empty($to)) {
                     unset($to_array[$key]);
                     continue;
                 }
                 $message->addBcc($to);
             }
             try {
                 $message->send();
                 $email_success = true;
             } catch (Exception $e) {
                 $email_success = $e->getMessage();
             }
             $this->viewPath = 'Emails/html';
             $this->layout = 'Emails/html/default';
             $this->set('dialog', true);
             if (empty($to_array)) {
                 $this->Session->setFlash('This certificate could not be emailed because no email addresses' . ' were supplied.');
             } else {
                 if (true === $email_success) {
                     $this->Session->setFlash('The following message was sent.');
                 } else {
                     $this->Session->setFlash('The following message could <strong>not</strong> be sent.');
                 }
             }
             return $this->render('certificate_of_completion');
         } else {
             return 'This certificate cannot be generated.';
         }
     }
 }
开发者ID:asadaqain,项目名称:Guide-on-the-Side,代码行数:88,代码来源:TutorialsController.php


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