12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- <?php
- /**
- * Created by PhpStorm.
- * User: xiaofeng
- * Date: 2018/6/11
- * Time: 上午9:28
- */
- namespace common\api;
- use Yii;
- use yii\log\FileTarget;
- class EmailServer {
- public function SendOut($emai,$title,$content)
- {
- $url = Yii::getAlias('@backend') . '/config/email.json';
- if (is_file($url))
- {
- try{
- $mail = Yii::$app->mailer->compose();
- $mail->setTo($emai);
- $mail->setSubject($title);
- $mail->setHtmlBody($content);
- if ($mail->send() == true){
- file_put_contents(Yii::getAlias('@common').'/log/success.email'.date('Y-m-d-H-i-s',$_SERVER['REQUEST_TIME']).'.'.rand(1,10).'.log',$content);
- return true;
- }
- }catch (\Exception $e){
- $log = new FileTarget();
- $log->logFile = Yii::getAlias('@common').'/log/email'.date('Ymd').'.log';
- $log->messages[] = [json_encode($e),1,'application',microtime(true)];
- $log->export();
- return false;
- }
- }
- $log = new FileTarget();
- $log->logFile = Yii::getAlias('@common').'/log/email'.date('Ymd').'.log';
- $log->messages[] = ['该文件不存在'.json_encode($url),1,'application',microtime(true)];
- $log->export();
- return false;
- }
- }
|