如何通过电子邮件发送oracle查询结果 我更喜欢附加到电子邮件作为Excel文件。

我需要使用PhpExcel和PhpMailer通过电子邮件发送该表作为Excel附件。 这个表是查询我的oracle数据库的结果。 我需要知道如何使用PhpExcel将此表写入excel,然后使用phpMailer将其附加到电子邮件地址,最后发送。 提前致谢。

<?php $username = "xxx"; $passwd = "yyy"; $db="(DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 123.43.56.789)(PORT = 1234)) ) (CONNECT_DATA = (SERVICE_NAME = xxx) ) )"; $c = OCILogon($username,$passwd,$db); if (!$c) { echo "Connection failed"; } else { echo "We are connected to KYC.Querying DB now...Please wait... "; } $s = oci_parse($c, " select MSISDN SUBSCRIBER_NUMBER, OUTLET_NUMBER,time_stamp, Company,NAMES SUBSCRIBER_NAME,GENDER, DOB DATE_OF_BIRTH,Dealer_name Dealer_name, Agent_name from subscribers where time_stamp between trunc(sysdate)-1 And trunc(sysdate)-1/86400 order by time_stamp"); if (!$s) { $e = oci_error($c); trigger_error('Could not parse statement: '. $e['message'], E_USER_ERROR); } $r = oci_execute($s); if (!$r) { $e = oci_error($s); trigger_error('Could not execute statement: '. $e['message'], E_USER_ERROR); } $html .= '<table width="720" border="0" cellspacing="0" cellpadding="0"> <tr> <th class="header" colspan="7"> KYC Details</th> <tr> <tr> <th>SUBSCRIBER_NUMBER</th> <th>OUTLET_NUMBER</th> <th>TIME_STAMP</th> <th>COMPANY</th> <th>SUBSCRIBER_NAME</th> <th>GENDER</th> <th>DATE_OF_BIRTH</th> <tr>'; while($rows=oci_fetch_array($s, OCI_ASSOC+OCI_RETURN_NULLS)){ $sub = $rows['SUBSCRIBER_NUMBER']; $agt = $rows['OUTLET_NUMBER']; $tim = $rows['TIME_STAMP']; $com = $rows['COMPANY']; $nam = $rows['SUBSCRIBER_NAME']; $sex = $rows['GENDER']; $dob = $rows['DATE_OF_BIRTH']; $html .= '<tr> <td>'.$sub.'</td> <td>'.$agt.'</td> <td>'.$tim.'</td> <td>'.$com.'</td> <td>'.$nam.'</td> <td>'.$sex.'</td> <td>'.$dob.'</td>'; $html .= '<tr>'; } $html .='</table><hr>'; echo $html; ?> 

我会忽略HTML的东西,并简单地写在每个logging后用逗号分隔的值文件,然后在Excel中打开并保存为XLSX。