【问题标题】:Mandrill with php to send .xls attachment, blank fileMandrill 与 php 发送 .xls 附件,空白文件
【发布时间】:2015-10-14 14:48:08
【问题描述】:

只有我一个人还是几乎没有关于如何做到这一点的文档? Mandrill 的网站没有多大帮助。不管怎样……问题来了……

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;
}

电子邮件发送正确,但我什至无法打开 .xls 文件。我尝试使用 'application/xls' 作为类型,但也没有用。我对编码不熟悉,请帮忙!

【问题讨论】:

    标签: php xls mandrill


    【解决方案1】:

    这一行:

    'path' => $attachment_encoded
    

    需要这样:

    'content' => $attachment_encoded
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-11-27
      • 2013-11-12
      • 1970-01-01
      • 1970-01-01
      • 2011-01-04
      • 2013-02-15
      • 1970-01-01
      相关资源
      最近更新 更多