2011-04-28 5 views
4

문제가 있습니다. CSV 파일을 만들어 특정 이메일에 첨부하여 보내야합니다. 정직하게 나는 그것을 결코하지 않는다. 그래서 나는이 문제에 아주 망치고있다. 아무도 내가 시작하거나 공유해야 할 링크를 말해 줄 수 있습니까?이메일에 첨부 된 CSV 파일 보내기

+3

당신은 어떤면을 가지고 있습니까? 어떤 코드가 있습니까? –

답변

18

나는 이것이 당신이 찾고있는 것이라고 생각하며, 나는 과거의 작품에서 그것을 완벽하게 사용했다.

희망이 있습니다.

<?php 
    $cr = "\n"; 
    $csvdata = "First Name" . ',' . "Last Name" . $cr; 
    $csvdata .= $txtFName . ',' . $txtLName . $cr; 

    $thisfile = 'file.csv'; 

    $encoded = chunk_split(base64_encode($csvdata)); 

    // create the email and send it off 

    $subject = "File you requested from RRWH.com"; 
    $from = "[email protected]"; 
    $headers = 'MIME-Version: 1.0' . "\n"; 
    $headers .= 'Content-Type: multipart/mixed; 
     boundary="----=_NextPart_001_0011_1234ABCD.4321FDAC"' . "\n"; 

    $message = ' 

    This is a multi-part message in MIME format. 

    ------=_NextPart_001_0011_1234ABCD.4321FDAC 
    Content-Type: text/plain; 
      charset="us-ascii" 
    Content-Transfer-Encoding: 7bit 

    Hello 

    We have attached for you the PHP script that you requested from http://rrwh.com/scripts.php 
    as a zip file. 

    Regards 

    ------=_NextPart_001_0011_1234ABCD.4321FDAC 
    Content-Type: application/octet-stream; name="'; 

    $message .= "$thisfile"; 
    $message .= '" 
    Content-Transfer-Encoding: base64 
    Content-Disposition: attachment; filename="'; 
    $message .= "$thisfile"; 
    $message .= '" 

    '; 
    $message .= "$encoded"; 
    $message .= ' 

    ------=_NextPart_001_0011_1234ABCD.4321FDAC-- 

    '; 

    // now send the email 
    mail($email, $subject, $message, $headers, "-f$from"); 
    ?> 

친절함에 대해서는 웨슬리.

+0

위대한 작품 !!!!! –

+0

문제 없으니 기꺼이 도와주세요! – Wesley

+0

위대한 대답, 고맙습니다, 웨슬리! – Kuen

관련 문제