2010-01-25 33 views
1

我有一個網絡表單,它允許我們的代理上傳一個pdf附件,稍後通過電子郵件發送給我們的客戶。我用來建立我在網站上找到的電子郵件的代碼,直到最近它似乎都運行良好。它似乎與一些(只有少數,例如Gmail)郵件客戶端附件打印出來的電子郵件的身體,而不是被解釋爲附件。它幾乎適用於我們嘗試過的幾乎每個客戶,只有少數客戶。爲什麼會發生這種情況的任何解決方案將不勝感激,因爲我對此沒有太多的瞭解。php郵件附件不能與一些客戶端合作

if ($_FILES["file"]["error"] > 0) 
{ 
echo "Error: " . $_FILES["file"]["error"] . "<br />"; 
return; 
} 
if ($_FILES["file"]["type"] != "application/pdf") 
{ 
echo "<center>Attachment has to be valid .pdf<br><a href='../index.php'>Tillbaka</a></center>"; 
return; 
} 
$file = chunk_split(base64_encode(file_get_contents($_FILES['file']['tmp_name']))); 
/* 
striped out some parts about how the body is constructed 
note that there are no comment fields here in the real version of this sourcecode. 
*/ 

$msg = "msg here.." //i striped this part out as there's nothing odd about how the body is constructed its plain text 

$random_hash = md5(date('r', time())); 

ob_start(); 
?> 
--PHP-mixed-<?php echo $random_hash; ?> 
Content-Type: multipart/alternative; boundary="PHP-alt-<?php echo $random_hash; ?>" 

--PHP-alt-<?php echo $random_hash; ?> 
Content-Type: text/plain; charset="iso-8859-1" 
Content-Transfer-Encoding: 7bit 

<?php echo $msg;?> 

--PHP-alt-<?php echo $random_hash; ?>-- 

--PHP-mixed-<?php echo $random_hash; ?> 
Content-Type: application/pdf; name="<?php echo $_FILES["file"]["name"];?>" 
Content-Transfer-Encoding: base64 
Content-Disposition: attachment 

<?php echo $file;?> 

--PHP-mixed-<?php echo $random_hash; ?>-- 
    <?php  
$message = ob_get_clean();  
//I removed some info about recievers, reply-to, from etc.. 
mail($hidden_variable, "hidden subject", $message, "From:Hidden Name <[email protected]>\r\nReply-To: [email protected]\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\""))  

回答

0

您無法提示客戶如何閱讀電子郵件。有些人太過聰明,會嘗試將附件包含在身體中,例如圖像通常包含在內。對此你可以做的不多。一種解決方案是將PDF存儲在您的服務器上,並通過電子郵件發送鏈接以供下載。

+0

嗨,是的,我開始明白這一點。但問題是,一切都通過我們的內聯網運行。網絡應用僅限於我們的支持人員使用我們的客戶,我們不能託管PDF文件的下載,我們也不應該因爲我們只是我們的taskmaster和他們的客戶之間的中間人。但是,如果我現在打開我的mailclient併發送一封電子郵件到一個帶有pdf附件的gmail,它可以正常工作。所以,我怎樣構建我的電子郵件,內容頭文件等等一些郵件客戶端不喜歡的東西一定是錯的。 – 2010-01-25 14:45:38

+0

你可以做的一件事是比較兩封電子郵件中的標題。 – Sqoo 2010-01-25 17:56:33

相關問題