2013-08-06 77 views
0

如何使用phpmailer以字符串形式發送文件?phpmailer附加文件

文件內容作爲BLOB存儲在Mysql中,但發送郵件時文件大小隻有2個字節?在數據庫中,大小約爲30kb?

$phpmailer->AddStringAttachment(
    base64_encode($row['file_data']), 
    $row['file_name'], 
    'base64', 
    $row['file_type'] 
); 

的數據是直接從不做任何處理MySQL數據庫牽強......

這將在瀏覽器中顯示的圖像

header('Content-type: '.$row['file_type']); 
echo $row['file_data']; 
+0

也許你的意思是'base64_encode()'而不是解碼? – Spudley

+0

當然.. :)現在的文件大小約爲40kb,但仍然無法打開該文件...出了點問題 – clarkk

+0

我已經爲你發佈了一個答案。總之 - 根本不要做任何編碼; phpMailer已經爲你做好了。我認爲這應該解決問題。 – Spudley

回答

1

首先,我想你大概意思base64_encode()而比解碼?

但是,我的猜測是,你可能根本不想編碼它 - phpMailer在內部爲你處理編碼,所以你不需要自己做任何base64編碼。

所以我認爲正確的答案是簡單地將數據傳遞給郵件程序而不進行任何編碼。

$phpmailer->AddStringAttachment(
    $row['file_data'], 
    $row['file_name'], 
    'base64', 
    $row['file_type'] 
); 

希望有幫助。