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

查看:213
本文介绍了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不会将文件的路径附件如果您使用send或send-template调用,附件应该是具有三个键的关联数组(hash):类型,名称和内容。

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.

content参数应该是作为Base64编码字符串的文件的内容,所以,而不是路径,你会想要获得文件内容,Base64编码它们,然后传递他们在一个参数 content 而不是 path

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天全站免登陆