Mandrill电子邮件附件文件路径 [英] Mandrill email attachments file path

查看:203
本文介绍了Mandrill电子邮件附件文件路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试添加一些附件到使用mandrill api通过php包装器发送的电子邮件。我尝试了许多不同的事情来尝试成功附加该文件,但无效。
我正在使用cakephp 2.x,但在这种情况下我觉得没有什么特别的意义(也许这样做?!)。
我正在使用由mandrill维护的php包装器,位于 https://bitbucket.org/mailchimp / mandrill-api-php

I am trying to add some attachments to an email that is being sent using the mandrill api via a php wrapper. I have tried a number of different things to try to successfully attach the file but to no avail. I am using cakephp 2.x but I don't think that has any particular significance in this instance (maybe it does?!). I am using the php wrapper maintained by mandrill at https://bitbucket.org/mailchimp/mandrill-api-php

这是代码:

$mandrill = new Mandrill(Configure::read('Site.mandrill_key'));
    $params = array(
        'html' => '
            <p>Hi '.$user['User']['name'].',</p>
            <p>tIt is that time of the year again.<br />
            <a href="http://my-site.com/members/renewal">Please login to the website members area and upload your renewal requirements</a>.</p>
            <p>Kind regards.</p>',
        "text" => null,
        "from_email" => Configure::read('Site.email'),
        "from_name" => Configure::read('Site.title'),
        "subject" => "Renewal Pending",
        "to" => array(array('email' => $user['User']['email'])),
        "track_opens" => true,
        "track_clicks" => true,
        "auto_text" => true,
        "attachments" => array(
            array(
                'path' => WWW_ROOT.'files/downloads/renewals',
                'type' => "application/pdf",
                'name' => 'document.pdf',
            )
        )
    );

    $mandrill->messages->send($params, true);

}

这表明附件已添加到电子邮件中,是一个pdf,但实际的pdf没有附加。
我也尝试通过将路径直接添加到文件中,如下所示:

This shows that an attachment has been added to the email and is a pdf but the actual pdf has not been attached. I also tried by adding the path directly onto the file as in:

"attachments" => array(
            array(
                'type' => "application/pdf",
                'name' => WWW_ROOT.'files/downloads/renewals/document.pdf',
            )

我已经搜索并阅读我可以找到的每篇文章,但找不到任何具体的参考如何指定mandrill正确附加我的附件的路径。

I have googled and read every article I can find but cannot find any specific reference as to how I should specify the path for mandrill to correctly attach my attachment.

任何帮助将不胜感激。

推荐答案

看起来你正在传递一个名为 path 的参数,但是Mandrill API不会将文件的路径附件如果您使用发送或发送模板调用,附件应该是一个关联数组(散列),其中包含三个键:类型,名称和内容。

It looks like you're passing a parameter called path, but the Mandrill API doesn't take the path of a file for attachments. If you're using the send or send-template call, attachments should be an associative array (hash) with three keys: type, name, and content.

内容参数应该是文件的内容作为Base64编码的字符串,因此,而不是路径,您将需要获取文件内容,Base64对它们进行编码,然后传递给我们n是一个名为 content 而不是路径的参数。

The content parameter should be the contents of the file as a Base64 encoded string, so instead of path, you'll want to get the file contents, Base64 encode them, and then pass them in a parameter called content instead of path.

您可以在Mandrill API文档中查看参数的完整详细信息(包括附件): https://mandrillapp.com/api/docs/messages.html#method=send

You can see the full details of the parameters, including for attachments, in the Mandrill API docs here: https://mandrillapp.com/api/docs/messages.html#method=send

这篇关于Mandrill电子邮件附件文件路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆