public function actionSendEmail() { $sendType = Yii::app()->request->getParam('sendType'); if (empty($sendType)) { exit; } $startTime = time(); if ($sendType === 'daytime') { $startTime = time() - 60 * 5; //8-23点,每5分钟触发一次 } elseif ($sendType === 'night') { $startTime = time() - 60 * 60 * 8; //晚上23-8点 在8点触发一次 } $status = 10; //取某个状态下的日志 $rentalcarsApiLog_model = RentalcarsApiLog::model()->findAll("ReturnTime>:returnTime and Status =:status", array(":returnTime" => $startTime, ":status" => $status)); $rentalcarsApiLog_count = count($rentalcarsApiLog_model); if ($rentalcarsApiLog_count > 0) { $message = '<b>来自:百程资源系统-生产环境</b><br/><br/>'; foreach ($rentalcarsApiLog_model as $key => $value) { $message .= '<b>编号:' . $value['Id'] . '<br/>'; $message .= '接口名称:' . $value['InterfaceName'] . '<br/>'; $message .= '请求时间:' . date('Y-m-d H:i:s', $value['RequestTime']) . '<br/>'; $message .= '返回状态:异常状态-' . $value['Status'] . '</b><br/>'; //$message.='<b>请求参数:</b><br/>'.$value['RequestParam'].'<br/>'; //$message.='<b>返回值(Xml格式):</b><br/>'.$value['ReturnXml'].'<br/>'; //$message.='<b>返回值(Json格式):</b><br/>'.$value['ReturnParam'].'<br/>'; $message .= '======================================================================='; $message .= '<br/>'; } //发送邮件 // $emailStatus= Email::sendEmail(CARRENTALAPI_REQUESTEMAIL,'国际租车日志',$message); $emailStatus = Email::sendEmail(CARRENTALAPI_REQUESTEMAIL, '国际租车日志', $message, "smtp.baicheng.com", CARRENTALAPI_SENDEMAIL_USERNAME, CARRENTALAPI_SENDEMAIL_PASSWORD, $attachment = false); if ($emailStatus) { echo 'send success!'; } else { echo 'send error!'; } } else { echo 'send content is null!'; } }