小编Dan*_*Dan的帖子

Swift Mailer附件

我正在使用PHP动态创建CSV,然后我需要将此CSV文件附加到Swift Mailer消息.我已经尝试在创建的文件上使用file_get_content以及在创建的文件上使用chunk_split(base64_encode(file_get_contents())以及在将文件写入磁盘之前附加文件.如果没有写入磁盘,我会在CSV中获得Rescource#183,并附加它与file_get_content我在CSV文件的每一行中只得到一个字符串,任何人都知道我做错了什么?

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($file);
    $attachment['name'] = $order.'order';
  EDIT            
 Mail::Send(1, 'order_conf', 'Order CSV Attachment', $success, 'test@email.com', Address, NULL, NULL, $attachment); // attach and send
      }
      }
Run Code Online (Sandbox Code Playgroud)

php csv attachment swiftmailer mailer

4
推荐指数
1
解决办法
1万
查看次数

标签 统计

attachment ×1

csv ×1

mailer ×1

php ×1

swiftmailer ×1