PHP后台隔5分钟发送email邮件
程序员文章站
2024-02-04 18:03:52
...
1.5分钟发送email,并且邮件内容为由html模板生成的table
while(1)
{
//ten minute
var_dump("check task, please don't close");
//send email
processDBData($db);
//process inventory state
processInventoryState($db,$tasks);
sleep(5*60);
}
//read table data from database
function processDBData($db)
{
$testplan_id = '';
$temp = '';
$TotalCaseNum = 0;
$projectName = '';
//check finished testplan table->tasks
$sql="SELECT TK.id,TK.send_email,TK.user_id,TK.build_id,TK.case_ids,TK.testplan_id,TK.flag,TK.total
from tasks AS TK WHERE current=total and flag='2' and ISNULL(send_email)";
$controlInfor = $db->get_recordset($sql);
if(null== $controlInfor)
{
return;
}
foreach($controlInfor as $key =>$item)
{
//open model html
$fModel = fopen("report.model","r");
if(null == $fModel)
{
var_dump("no model");
}
$Modelhandle = fread($fModel,filesize("report.model"));
$test_cases = $item['case_ids'];
//get total Num
$TotalCaseNum = (int)$item['total'];
//testplan table->testplan
//$sql = "SELECT notes,testproject_id FROM testplans WHERE id='{$item['testplan_id']}'";
$sql = "SELECT name from nodes_hierarchy WHERE id='{$item['testplan_id']}'";
$result = $db->get_recordset($sql);
$temp = str_replace("MODEL_TESLPLANE",$result[0]['name'],$Modelhandle);
$Modelhandle = $temp;
//product table->testprojects
$sql = "SELECT notes FROM testprojects WHERE id='{$result[0]['testproject_id']}'";
var_dump($sql);
$result = $db->get_recordset($sql);
$temp = str_replace("MODEL_PRODUCTNAME",$result[0]['notes'],$Modelhandle);
$Modelhandle = $temp;
//build table->builds
$sql = "SELECT DB.name FROM builds AS DB WHERE testplan_id='{$item['testplan_id']}' and id='{$item['build_id']}'";
$result = $db->get_recordset($sql);
var_dump($sql);
$temp = str_replace("MODEL_BUILD",$result[0]['name'],$Modelhandle);
$projectName = $result[0]['name'];
$Modelhandle = $temp;
//test result table->executions
$cases = explode(',',$test_cases);
$case_infor = get_ts_name_details($db,$cases);
//var_dump(sizeof($case_infor));
//process html testcase content nl2br()
//after the content added(table,body,html end flag)
var_dump($case_infor);
$BeforSuiteNam = "";
$successNum = 0;
$TESTNUM = 0;
//var_dump($case_infor);
//var_dump($case_infor);
foreach($case_infor as $k=>$case)
{
$Modelhandle = $temp;
if($case['tsuite_name'] != $BeforSuiteNam)
{
$Modelhandle = $temp . "{$case['tsuite_name']} ";
$temp = $Modelhandle;
}
//cese name + importance + result
//var_dump(Integer.parseInt('c'));
//get success number
$sql="SELECT TK.id,TK.send_email,TK.user_id,TK.case_ids,TK.testplan_id,TK.flag,TK.total,TK.user_id from tasks AS TK WHERE current=total and flag='2'";
$controlInfor = $db->get_recordset($sql);
//set pass/fail information
//var_dump($case['status']);
$pass = 'p';
$finish ='c';
if(($case['status'])== $finish)//$TotalCaseNum
{
//set case information
$Modelhandle = $temp. "
{$case['name']}
{$case['importance']}
FINISH
";
}
else if($case['status'] == $pass)//$TotalCaseNum
{
$successNum++;
//set case information
$Modelhandle = $temp. "
{$case['name']}
{$case['importance']}
PASS
";
}
else
{
$Modelhandle = $temp. "
{$case['name']}
{$case['importance']}
FAIL
";
}
$temp = $Modelhandle;
$BeforSuiteNam = $case['tsuite_name'];
}
//set success number
//var_dump($TotalCaseNum);
//$TotalCaseNum
$temp = str_replace("MODEL_SUCCESS","{$successNum}/{$TotalCaseNum}",$Modelhandle);
$Modelhandle = $temp;
$temp = str_replace("MODEL_FAIL",($TotalCaseNum-$successNum)."/".$TotalCaseNum,$Modelhandle);
$Modelhandle = $temp;
//added html end sign
$Modelhandle = $temp . "
while(1)
{
//ten minute
var_dump("check task, please don't close");
//send email
processDBData($db);
//process inventory state
processInventoryState($db,$tasks);
sleep(5*60);
}
//read table data from database
function processDBData($db)
{
$testplan_id = '';
$temp = '';
$TotalCaseNum = 0;
$projectName = '';
//check finished testplan table->tasks
$sql="SELECT TK.id,TK.send_email,TK.user_id,TK.build_id,TK.case_ids,TK.testplan_id,TK.flag,TK.total
from tasks AS TK WHERE current=total and flag='2' and ISNULL(send_email)";
$controlInfor = $db->get_recordset($sql);
if(null== $controlInfor)
{
return;
}
foreach($controlInfor as $key =>$item)
{
//open model html
$fModel = fopen("report.model","r");
if(null == $fModel)
{
var_dump("no model");
}
$Modelhandle = fread($fModel,filesize("report.model"));
$test_cases = $item['case_ids'];
//get total Num
$TotalCaseNum = (int)$item['total'];
//testplan table->testplan
//$sql = "SELECT notes,testproject_id FROM testplans WHERE id='{$item['testplan_id']}'";
$sql = "SELECT name from nodes_hierarchy WHERE id='{$item['testplan_id']}'";
$result = $db->get_recordset($sql);
$temp = str_replace("MODEL_TESLPLANE",$result[0]['name'],$Modelhandle);
$Modelhandle = $temp;
//product table->testprojects
$sql = "SELECT notes FROM testprojects WHERE id='{$result[0]['testproject_id']}'";
var_dump($sql);
$result = $db->get_recordset($sql);
$temp = str_replace("MODEL_PRODUCTNAME",$result[0]['notes'],$Modelhandle);
$Modelhandle = $temp;
//build table->builds
$sql = "SELECT DB.name FROM builds AS DB WHERE testplan_id='{$item['testplan_id']}' and id='{$item['build_id']}'";
$result = $db->get_recordset($sql);
var_dump($sql);
$temp = str_replace("MODEL_BUILD",$result[0]['name'],$Modelhandle);
$projectName = $result[0]['name'];
$Modelhandle = $temp;
//test result table->executions
$cases = explode(',',$test_cases);
$case_infor = get_ts_name_details($db,$cases);
//var_dump(sizeof($case_infor));
//process html testcase content nl2br()
//after the content added(table,body,html end flag)
var_dump($case_infor);
$BeforSuiteNam = "";
$successNum = 0;
$TESTNUM = 0;
//var_dump($case_infor);
//var_dump($case_infor);
foreach($case_infor as $k=>$case)
{
$Modelhandle = $temp;
if($case['tsuite_name'] != $BeforSuiteNam)
{
$Modelhandle = $temp . "
$temp = $Modelhandle;
}
//cese name + importance + result
//var_dump(Integer.parseInt('c'));
//get success number
$sql="SELECT TK.id,TK.send_email,TK.user_id,TK.case_ids,TK.testplan_id,TK.flag,TK.total,TK.user_id from tasks AS TK WHERE current=total and flag='2'";
$controlInfor = $db->get_recordset($sql);
//set pass/fail information
//var_dump($case['status']);
$pass = 'p';
$finish ='c';
if(($case['status'])== $finish)//$TotalCaseNum
{
//set case information
$Modelhandle = $temp. "
}
else if($case['status'] == $pass)//$TotalCaseNum
{
$successNum++;
//set case information
$Modelhandle = $temp. "
}
else
{
$Modelhandle = $temp. "
}
$temp = $Modelhandle;
$BeforSuiteNam = $case['tsuite_name'];
}
//set success number
//var_dump($TotalCaseNum);
//$TotalCaseNum
$temp = str_replace("MODEL_SUCCESS","{$successNum}/{$TotalCaseNum}",$Modelhandle);
$Modelhandle = $temp;
$temp = str_replace("MODEL_FAIL",($TotalCaseNum-$successNum)."/".$TotalCaseNum,$Modelhandle);
$Modelhandle = $temp;
//added html end sign
$Modelhandle = $temp . "
推荐阅读
-
PHP后台隔5分钟发送email邮件
-
后台隔5分钟发送email,email内容为html
-
email.class.php 发邮件类,如何发送密送邮件
-
PHP后台隔5分钟发送email邮件
-
Zend Framework框架之Zend_Mail实现发送Email邮件验证功能及解决标题乱码的方法_PHP
-
email.class.php 发邮件类,如何发送密送邮件
-
Zend Framework框架之Zend_Mail实现发送Email邮件验证功能及解决标题乱码的方法_PHP
-
email.class.php 发邮件类,如何发送密送邮件
-
email - php如何发送电子邮件。如果是mail函数,需要本地配置邮件系统
-
php发送邮件方法-亲测可用,email.class.php过期解决办法