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; } }