2012-05-08 16 views
6

मैं php कोई समस्या के माध्यम से एक ईमेल भेज रहा हूं। मैं प्रदान की गई HTML ईमेल के साथ एक .csv फ़ाइल संलग्न करना चाहता हूं। मुझे यह नहीं लगता कि यह कैसे करना है। क्या $headers में Content-Dispositionअनुलग्नक के साथ $headers में भी एक निश्चित सामग्री-प्रकार शामिल करना है?php .csv अटैचमेंट के साथ एचटीएमएल ईमेल भेजें

$to = '[email protected]'; 
$subject = 'A Subject Line'; 
$headers = 'MIME-Version: 1.0' . "\r\n"; 
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; 

$message = " 
<html> 
<head> 
    <title>List of New Price Changes</title> 
</head> 
<body>"; 

$message .="HTML table"; 
$message .="</body></html>"; 

mail($to, $subject, $message, $headers); 
+0

संभावित डुप्लिकेट [ईमेल से जुड़ी सीएसवी फ़ाइल भेजें] (http://stackoverflow.com/questions/5816421/send-csv-file-attached-to-the-email) – nickb

+0

हाँ मैंने उस पोस्ट को देखा लेकिन यह यह समझाता नहीं है कि मल्टीपार्ट संदेशों जैसे कि मुझे लगता है कि मैं क्या देख रहा हूं – ToddN

उत्तर

19
$fileatt_type = "text/csv"; 
$myfile = "myfile.csv"; 

     $file_size = filesize($myfile); 
     $handle = fopen($myfile, "r"); 
     $content = fread($handle, $file_size); 
     fclose($handle); 

     $content = chunk_split(base64_encode($content)); 

     $message = "<html> 
<head> 
    <title>List of New Price Changes</title> 
</head> 
<body><table><tr><td>MAKE</td></tr></table></body></html>"; 

     $uid = md5(uniqid(time())); 

     #$header = "From: ".$from_name." <".$from_mail.">\r\n"; 
     #$header .= "Reply-To: ".$replyto."\r\n"; 
     $header .= "MIME-Version: 1.0\r\n"; 
     $header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n"; 
     $header .= "This is a multi-part message in MIME format.\r\n"; 
     $header .= "--".$uid."\r\n"; 
     $header .= "Content-type:text/html; charset=iso-8859-1\r\n"; 
     $header .= "Content-Transfer-Encoding: 7bit\r\n\r\n"; 
     $header .= $message."\r\n\r\n"; 
     $header .= "--".$uid."\r\n"; 
     $header .= "Content-Type: text/csv; name=\"".$myfile."\"\r\n"; // use diff. tyoes here 
     $header .= "Content-Transfer-Encoding: base64\r\n"; 
     $header .= "Content-Disposition: attachment; filename=\"".$myfile."\"\r\n\r\n"; 
     $header .= $content."\r\n\r\n"; 
     $header .= "--".$uid."--"; 

mail($to, $subject, $message, $header); 

अपनी स्थिति के लिए कोड को संशोधित करने का प्रयास करें।

+0

क्या यह "बाउंड बाउंड बाउंड" जैसी सरल सीमा के लिए काम करेगा? – ToddN

+1

आप अपनी सीमा क्यों लगाते हैं? कोड आपको एक अच्छा गणना करता है। –

+0

आह ठीक है, roger कि, अब परीक्षण, धन्यवाद – ToddN

1

आप मेल के साथ भ्रमित HTTP हेडर कर रहे हैं .... आप शायद एक multipart messages भेजना चाहते हैं, लेकिन यह reimplementing के बजाय, मैं PHPMailer की तरह कुछ के लिए जाना चाहते हैं।

संबंधित मुद्दे