Beispiel #1
0
 public function send($arr)
 {
     $recipientsMailboxs = Mailbox::find()->where(['type' => 1])->all();
     $addresserMailbox = Mailbox::find()->where(['type' => 0])->all();
     $email = $addresserMailbox[array_rand($addresserMailbox, 1)];
     $path = Yii::getAlias('@webroot') . '/../config/mailer.php';
     $fh = fopen($path, "r+");
     $new_content = '<?php return [\'sendEmailUser\' => \'' . $email->email_address . '\',\'sendEmailPassword\' => \'' . $email->password . '\',\'messageConfigFrom\' => \'' . $email->email_address . '\'];';
     if (flock($fh, LOCK_EX)) {
         //加写锁
         ftruncate($fh, 0);
         // 将文件截断到给定的长度
         rewind($fh);
         // 倒回文件指针的位置
         fwrite($fh, $new_content);
         flock($fh, LOCK_UN);
         //解锁
     }
     fclose($fh);
     if ($arr['type'] == 1) {
         $arr['luckyStr'] ? $luckyStr = '<br/>' . str_replace("\r\n", '<br/>', $arr['luckyStr']) : ($luckyStr = '没有中奖 T.T');
         $regretStr = str_replace("\r\n", '<br/>', $arr['regretStr']);
         $html = '<a href="http://' . $_SERVER['SERVER_NAME'] . '">传送门--->小蛮牛数据平台</a><br/>' . '<a href="' . $this->shishicaiUrl[$arr['urlName']] . '">传送门--->' . $arr['urlName'] . '</a><br/>' . '当前彩种:' . $arr['urlName'] . ' - [新时时彩]<br/>' . '当前期号:' . $arr['qihao'] . '<br/>' . '开奖号码:' . implode(",", $arr['codeArr']) . '<br/>' . '中奖号码:' . $luckyStr . '<br/>' . '未中奖号码:<br/>' . $regretStr;
     }
     if ($arr['type'] == 2) {
         $html = '新-N-' . $arr['regret_number'];
         /*
         $html = '报警提醒:<br/>当前'.$arr['regret_number']
             .'期内 没有一组中奖号码!!!!!!<br/>'
             .'<a href="http://'.$_SERVER['SERVER_NAME'].'">传送门--->小蛮牛数据平台</a><br/>'
             .'以下是彩种信息:<br/><br/>';
         
         foreach($arr['NewestCodes'] as $newstcode){
             $lucky_txt = '没有中奖 T.T';
         
             $url = array_keys($this->codeType, $newstcode->type);
             $url = $url[0];
             $urlName = array_keys($this->urlArr, $url);
             $urlName = $urlName[0];
             $shishicaiUrl = $this->shishicaiUrl[$urlName];
         
             $html .= '<a href="'.$shishicaiUrl.'">传送门--->'.$urlName.'</a><br/>'
                 .'当前彩种:'.$urlName.' - [新时时彩]<br/>'
                 .'当前期号:'.$newstcode->qishu .'<br/>'
                 .'开奖号码:'. $newstcode->one.','.$newstcode->two.','.$newstcode->three.','.$newstcode->four.','.$newstcode->five .'<br/>'
                 .'中奖状态:'. $lucky_txt .'<br/><br/>';
         }
         */
     }
     foreach ($recipientsMailboxs as $obj) {
         $mail = Yii::$app->mailer->compose();
         $mail->setTo($obj->email_address);
         //            $mail->setSubject("小蛮牛提醒");
         $mail->setSubject("机房提醒");
         //$mail->setTextBody('zheshisha');   //发布纯文字文本
         $mail->setHtmlBody($html);
         //发布可以带html标签的文本
         if ($mail->send()) {
             if ($arr['type'] == 1) {
                 $emailType = '每一期中奖邮寄通知  ';
             } else {
                 $emailType = 'N期未中奖邮件通知  ';
             }
             echo $emailType . "邮件通知发送成功.success<br/>";
         } else {
             echo "邮件通知发送失败.failse";
         }
     }
 }
Beispiel #2
0
 /**
  * 发送邮件
  * @param $content  邮件内容;
  */
 private function send_mail($content)
 {
     //配置文件的 发件人地址
     $sendEmailUser = Yii::$app->params['sendEmailUser'];
     /* 将最新的发件人配置信息 写入配置文件 */
     $addresserMailbox = Mailbox::find()->where(['type' => 0])->all();
     $email = $addresserMailbox[array_rand($addresserMailbox, 1)];
     //数据库里的 发件人地址 与 配置文件不同时 则更新配置文件
     if ($sendEmailUser != $email) {
         $path = Yii::getAlias('@webroot') . '/../config/mailer.php';
         $fh = fopen($path, "r+");
         $new_content = '<?php return [\'sendEmailUser\' => \'' . $email->email_address . '\',\'sendEmailPassword\' => \'' . $email->password . '\',\'messageConfigFrom\' => \'' . $email->email_address . '\'];';
         if (flock($fh, LOCK_EX)) {
             //加写锁
             ftruncate($fh, 0);
             // 将文件截断到给定的长度
             rewind($fh);
             // 倒回文件指针的位置
             fwrite($fh, $new_content);
             flock($fh, LOCK_UN);
             //解锁
         }
         fclose($fh);
     }
     //收件人列表
     $recipientsMailboxs = Mailbox::find()->where(['type' => 1])->all();
     foreach ($recipientsMailboxs as $key => $obj) {
         $mail = Yii::$app->mailer->compose();
         $mail->setTo($obj->email_address);
         //            $mail->setSubject("小蛮牛提醒");
         $mail->setSubject("机房提醒");
         //$mail->setTextBody('zheshisha');   //发布纯文字文本
         $mail->setHtmlBody($content);
         //发布可以带html标签的文本
         if ($mail->send()) {
             echo $this->cptype . "预定号码报警 邮件发送成功 时间:" . date('Y-m-d H:i:s') . "\r\n";
         } else {
             echo $this->cptype . "预定号码报警 邮件通知发送失败,请尽快与管理员联系 时间:" . date('Y-m-d H:i:s') . "\r\n";
         }
     }
 }