5-minute background send Email,email content as HTML

Source: Internet
Author: User
Tags fread word wrap testlink






























































";$temp = $Modelhandle;}Cese name + importance + ResultVar_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 informationVar_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 NumberVar_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. "
1.5 minutes email, and the message content is a table generated by an HTML template
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 ']}
{$case [' name ']} {$case [' Importance ']} FINISH
{$case [' name ']} {$case [' Importance ']} PASS
{$case [' name ']} {$case [' Importance ']} FAIL


";

$fHtml = fopen ("report.html", "w");

if (fwrite ($fHtml, $Modelhandle))
{
Fclose ($fModel);
Fclose ($fHtml);
Die ("Create HTML Success");
}
Else
{
Fclose ($fModel);
Fclose ($fHtml);
}

Get email address and send email
$sql = "Select Email,group_email from Users WHERE id={$item [' user_id ']}";
Var_dump ($sql);

$result = $db->get_recordset ($sql);

if (SendEmail ($result [0][' email '], $result [0][' Group_email '], $projectName))
{
Signfinishemail ($db, $item [' id ']);
}

$successNum = 0;
}

Get test Case
return true;
}

Sign finish send email flag
function Signfinishemail ($db, $TaskId)
{
$sql = "UPDATE tasks SET send_email= ' 1 ' WHERE id= ' {$TaskId} '";
Var_dump ($sql);
$db->exec_query ($sql);
Return
}

Create email Conttent
function createhtml ()
{
$fModel = fopen ("Report.model", "R");

if ($fModel)
{
$handle = Fread ($fModel, FileSize ("Report.model"));
Var_dump ($handle);
$fHtml = fopen ("report.html", "w");

if (fwrite ($fHtml, $handle))
{
Fclose ($fModel);
Fclose ($fHtml);
}
Else
{
Fclose ($fModel);
Fclose ($fHtml);
Die ("Create html sucess");
}
}
Return
}

/*
Function:get_ts_name_details

Args:

Returns:map with Key=tcid
Values= Assoc_array ([tsuite_id = 5341
[Details] = my Detailas ts1
[Tcid] = 5343
[Tsuite_name] = ts1)
*/
Function Get_ts_name_details (& $db, $tcase _id)
{
$tables = Array ();
$termCase = $tcase _id;

$tables [' testsuites '] = db_table_prefix. ' Testsuites ';
$tables [' nodes_hierarchy '] = db_table_prefix. ' Nodes_hierarchy ';

$rs = ";
$do _query = true;
$sql = "Select Ts.id as tsuite_id, Ts.details, Tcs.status,
Nha.id as tc_id, nha.name,nhb.name as Tsuite_name,tv.importance
from {$tables [' testsuites ']} TS, {$tables [' Nodes_hierarchy ']} NHA,
{$tables [' Nodes_hierarchy ']} Nhb,tcversions tv,executions TCS
WHERE ts.id=nha.parent_id
and nhb.id=nha.parent_id
and tcs.tcversion_id=nha.id+1
and tv.id=nha.id+1 ";

if (Is_array ($tcase _id) && count ($tcase _id) > 0)
{
Note Start node
$tcase _id[count ($tcase _id)-1]-= 1;

$in _list = Implode ("-1,", $tcase _id);

$sql. = "and Nha.id in (". $in _list. ")";
}
else if (!is_null ($tcase _id))
{
$sql. = "and nha.id={$tcase _id}";
}
Else
{
$do _query = false;
}
if ($do _query)
{
Var_dump ($sql);
$rs = $db->fetchrowsintomap ($sql, ' tc_id ');
}

return $rs;
}

Send email
function SendEmail ($emailAdress, $groupEmail, $projectName)
{
$MailTital = "HATP:". $projectName;
Var_dump ($groupEmail);
if ($emailAdress = = "")
{
return false;
}

if (null! = $groupEmail)
{
Var_dump ("Run Here");
$ReciveEmails = Explode (";", $groupEmail);
}

Process email Informaition
$mail = new Phpmailer (true); New instance, with exceptions enabled

$body = file_get_contents (' report.html ');
Var_dump ($body);
$body = preg_replace ('/\\\\/', ' ', $body); Strip backslashes

$mail->issmtp (); Tell the class to use SMTP
$mail->smtpauth = true; Enable SMTP Authentication
$mail->port = 25; Set the SMTP server port
$mail->host = "172.20.0.6"; SMTP Server
$mail->username = "bugfree@hojy.com"; SMTP Server username
$mail->password = "Bugfree"; SMTP Server Password
$mail->from = "Testlink";
$mail->fromname = "Testlink";
$mail->subject = $MailTital;
$mail->altbody = "To view the message, please use an HTML compatible email viewer!"; Optional, comment out and test
$mail->wordwrap = 80; Set word Wrap
$mail->msghtml ($body);
$mail->ishtml (TRUE); Send As HTML

Add tester
$ReciveEmails [sizeof ($ReciveEmails)] = $emailAdress;
Var_dump ($ReciveEmails);
foreach ($ReciveEmails as $K = $Item)
{
Var_dump ($Item);
$mail->addaddress ($Item);//to Send Man
}

Try
{
$mail->send ();
}
catch (Phpmailerexception $e)
{
echo $e->errormessage ();
return false;
}

$ReciveEmails = ";
return TRUE;
}
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.