douxuanpa8298 2015-07-24 03:52
浏览 63

Mandrill用php发送.xls附件,空白文件

Is it just me or is there almost no documentation on how to do this? Mandrill's site isn't much help. Anyway...here's the problem...

try {
    $mandrill = new Mandrill('API_KEY');
    $attachment = file_get_contents("../template.xls");
    $attachment_encoded = base64_encode($attachment);
    $message = array(
        'html' => '<p>Some html text</p>',
        'text' => 'Some text',
        'subject' => 'Subject',
        'from_email' => 'email@domain.com',
        'from_name' => 'Name',
        'to' => array(
            array(
                'email' => 'myemail@domain.com',
                'name' => 'Name',
                'type' => 'to'
            )
        ),
        'attachments' => array(
            array(
                'type' => 'application/vnd.ms-excel',
                'name' => 'New_Features_Submission.xls',
                'path' => $attachment_encoded
            )
        )
    );
    $async = false;
    $result = $mandrill->messages->send($message, $async);
    print_r($result);
} catch (Mandrill_Error $e) {
    echo 'A Mandrill error occured: ' . get_class($e) . '-' . $e->getMessage();
    throw $e;
}

The email sends correctly, but I can't even open the .xls file. I tried using 'application/xls' for the type, that didn't work either. I'm not familiar with encoding, help please!

  • 写回答

1条回答 默认 最新

  • duandang2838 2015-07-24 18:34
    关注

    This line:

    'path' => $attachment_encoded
    

    Needs to be this:

    'content' => $attachment_encoded
    
    评论

报告相同问题?

悬赏问题

  • ¥15 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序
  • ¥15 onvif+openssl,vs2022编译openssl64
  • ¥15 iOS 自定义输入法-第三方输入法
  • ¥15 很想要一个很好的答案或提示