2011-01-12 4 views
1

PHPで.CSVファイルを送信しようとしています。ファイルは送信前にディスクに書き込まれますが、file_get_contents()でファイルを添付しようとすると、 .CSVの構造はまだ送信される前に作成されたファイルを送信して送信するとリソースID(#183)が得られるので、ユーザーが.CSVファイルとして開くことができるファイルをどのように添付できますか?私はあなたがちょうどattach the file directlyをすることができ、file_get_contents()の必要がない、Swift Mailerのを使用している場合、MIMEタイプとヘッダがCSV file_get_contents PHPを送信

EDIT

if(!file_exists(_PS_ORDERS_DIR_.$orderDate.'/'.$file_name.'.csv')) 
{ 
     if($file = fopen (_PS_ORDERS_DIR_.$orderDate.'/'.$file_name.'.csv', 'x+')) 
     { 
     foreach ($list as $fields) 
      { 
       fputcsv($file, $fields); 
      } 


      $attachment['mime'] = 'application/vnd.ms-excel'; 
      $attachment['content'] = file_get_contents(_PS_ORDERS_DIR_.$orderDate.'/'.$file_name.'.csv'); 
      $attachment['name'] = $order.'order'; 

    Mail::Send(1, 'order_conf', 'Order CSV Attachment', $success, '[email protected]', CakeToppers, NULL, NULL, $attachment); 
    return true; 
     } 
+2

私は問題は 'のfile_get_contents()'だと思うドント。どのようにファイルを追加してメッセージを送信していますか? – jeroen

+4

いくつかのコードを表示できますか? –

+0

私は電子メールを送るためにスウィフトメーラーを使用しています。私はfile_get_contents()やfopen()のようなものを使ってしばらく前にこの作業をしていたことを覚えていますが、文字列とリソースでそれらを使用しても運がないという組み合わせはすべて試しました。私はCSVファイルが作成されたら、それらを見ることができるので、CSVファイルが正常に作成されていることを知っています。 – Dan

答えて

1

正しいことを確認作りました。

Swift Mailerのドキュメントから:あなたのためにそう

//Create the attachment 
// * Note that you can technically leave the content-type parameter out 
$attachment = Swift_Attachment::fromPath('/path/to/image.jpg', 'image/jpeg'); 

//Attach it to the message 
$message->attach($attachment); 

それは次のようになります。

$attachment = Swift_Attachment::fromPath(_PS_ORDERS_DIR_.$orderDate.'/'.$file_name.'.csv', 'application/vnd.ms-excel'); 

//Attach it to the message 
$message->attach($attachment);