Esempio n. 1
0
 public function actionAdmin()
 {
     $model = new Mail();
     //$model->unsetAttributes();  // clear any default values
     $model->load(Yii::$app->request->get());
     //$model->attributes = $_GET['Mail'];
     return $this->render('admin', array('model' => $model));
 }
Esempio n. 2
0
 /**
  * Creates a new Mail model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Mail();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
 public function actionRewrite($email_id, $subject, $receiver, $text, $check_user)
 {
     $model = new Mail();
     $message = true;
     $session = Yii::$app->session;
     //$check_users=Users::find()->where(['permission'=>2])->asArray()->all();
     // print_r($check_users);
     if ($model->load(Yii::$app->request->post())) {
         //粘贴部分
         $mailaccount = Setting::find()->one();
         $sendhost = $mailaccount->sendhost;
         $username = $mailaccount->username;
         $user = $mailaccount->user;
         $password = $mailaccount->password;
         error_reporting(E_ALL ^ E_WARNING);
         $request = Yii::$app->request;
         $body = $request->post();
         $to = $model->receiver;
         $subject = $model->subject;
         $model->file = UploadedFile::getInstance($model, 'file');
         //error_reporting(E_ALL^E_WARNING);
         // $request = Yii::$app->request;
         //$body = $request->post();
         //$to=$model->receiver;
         //            $text=$model->text;
         // $subject=$model->subject;
         //            $body = $model->body;
         //print_r($model);
         //粘贴部分
         if ($model->file != null) {
             $filename = $model->file->name;
             $encode = mb_detect_encoding($filename, array("ASCII", "UTF-8", "GBK", "GB2312"));
             if ($encode == "EUC-CN") {
                 $encode = "GB2312";
             }
             if ($encode != "GBK") {
                 $filename = iconv($encode, "GBK//IGNORE", $filename);
             }
             //echo $filename."before save"."</br>";
             if ($model->file->saveAs('../attachment/sendattachment/' . $filename)) {
                 $mail = new sendmail();
                 //新建发送
                 $mail->setServer($sendhost, $user, $password);
                 $mail->setFrom($username);
                 $mail->setReceiver("{$to}");
                 $mail->setMailInfo($subject, $body['body'], '../attachment/sendattachment/' . $filename);
                 $message = true;
                 //插入check表
                 //$check_user=$_POST['check_user'];
                 if ($check_user != NULL) {
                     //更新sent邮件列表
                     $sent_email = SentEmail::findOne($email_id);
                     $sent_email->subject = $subject;
                     $sent_email->receiver = $to;
                     $sent_email->text = $body['body'];
                     $sent_email->attachment = '../attachment/sendattachment/' . $filename . ';';
                     //$sent_email->sender=$username;
                     //$sent_email->user_id=$session['user_id'];
                     $sent_email->save();
                     $ck = Check::find()->where(['email_id' => $email_id])->one();
                     //$check->user_id=$session['user_id'];
                     $ck->check_status = 0;
                     $ck->save();
                     return $this->redirect('?r=site/checkself&user_id=' . $session['user_id'] . '&check_status=0');
                 } else {
                     if (!$mail->sendMail()) {
                         $message = false;
                         return $this->render('rewrite', ['model' => $model, 'subject' => $subject, 'receiver' => $receiver, 'text' => $text, 'check_users' => $check_users]);
                     }
                     //$time=date("Y-m-d H:i:s",time());
                     $session = Yii::$app->session;
                     $sent_email = new SentEmail();
                     $sent_email->subject = $subject;
                     $sent_email->receiver = $to;
                     $sent_email->text = $body['body'];
                     $sent_email->attachment = '../attachment/sendattachment/' . $filename . ';';
                     $sent_email->sender = $username;
                     $sent_email->user_id = $session['user_id'];
                     $sent_email->save();
                     return $this->redirect('?r=site/sent&user_id=' . $session['user_id']);
                 }
             }
         } else {
             $mail = new sendmail();
             //新建发送
             $mail->setServer($sendhost, $user, $password);
             $mail->setFrom($username);
             $mail->setReceiver("{$to}");
             $mail->setMailInfo($subject, $body['body'], "");
             //插入已发送列表
             //插入check表
             //$check_user=$_POST['check_user'];
             if ($check_user != NULL) {
                 //$time=date("Y-m-d H:i:s",time());
                 $sent_email = SentEmail::findOne($email_id);
                 $sent_email->subject = $subject;
                 $sent_email->receiver = $to;
                 $sent_email->text = $body['body'];
                 //$sent_email->attachment='../attachment/sendattachment/'.$filename.';';
                 //$sent_email->sender=$username;
                 //$sent_email->user_id=$session['user_id'];
                 $sent_email->save();
                 $ck = Check::find()->where(['email_id' => $email_id])->one();
                 //$check->user_id=$session['user_id'];
                 $ck->check_status = 0;
                 $ck->save();
                 //print_r($check['user_id']);
                 return $this->redirect('?r=site/checkself&user_id=' . $session['user_id'] . '&check_status=0');
             } else {
                 if (!$mail->sendMail()) {
                     $message = false;
                     return $this->render('rewrite', ['model' => $model, 'subject' => $subject, 'receiver' => $receiver, 'text' => $text, 'check_user' => $check_user]);
                 }
                 //$time=date("Y-m-d H:i:s",time());
                 $session = Yii::$app->session;
                 $sent_email = new SentEmail();
                 $sent_email->subject = $subject;
                 $sent_email->receiver = $to;
                 $sent_email->text = $body['body'];
                 //$sent_email->attachment='../attachment/sendattachment/'.$filename.';';
                 $sent_email->sender = $username;
                 $sent_email->user_id = $session['user_id'];
                 $sent_email->save();
                 return $this->redirect('?r=site/sent&user_id=' . $session['user_id']);
             }
         }
     } else {
         return $this->render('rewrite', ['model' => $model, 'subject' => $subject, 'receiver' => $receiver, 'text' => $text, 'check_user' => $check_user]);
     }
 }