我需要發送帶附件的電子郵件,並且該附件文件包含一些同時從mysql數據庫獲取的數據。從mysql創建excel並將其作爲附件郵件發送到php
這個問題已經被詢問和描述here但沒有任何工作答案。 任何人都可以有解決方案,比請回答。
while($row = mysql_fetch_row($sqlQuery))
{
$line = '';
foreach($row as $value)
{
if ((!isset($value)) || ($value == ""))
{
$value = "\t";
}
else
{
$value = str_replace('"' , '""' , $value);
$value = '"' . $value . '"' . "\t";
}
$line .= $value;
}
$data .= trim($line) . "\n";
}
$data = str_replace("\r" , "" , $data);
$cho = "$header\n$data";
echo $cho;
$headers = "From:[email protected](PFC Web Admin) \r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: application/vnd.ms-excel";
$headers .= 'Content-Disposition: attachment; filename=Test.xls' . "\r\n";
$headers .= "Content-Transfer-Encoding: base64\r\n";
$headers .= "".$cho."\r\n";
$subject = 'Record November';
$mail = mail('[email protected]', $subject, $msg, $headers);
if($mail == true)
{
echo "Message successfully sent";
}
else
{
echo "Message could not be sent";
}
Excel正在創建並具有適當的數據,但我需要郵寄而不是下載。
這就是問題所在,我需要爲這兩個問題的解決方案。 – 2014-10-16 11:08:07
我不認爲你會發現。兩個問題需要兩個解決方案。使用一種解決方案,您可以製作Excel文件,並通過電子郵件發送給其他人。把東西放在一起,讓它做你想做的,是編程的基礎。 – 2014-10-16 12:31:44