我正在尝试向通过 php 包装器使用 mandrill api 发送的电子邮件添加一些附件。我尝试了很多不同的方法来尝试成功附加文件,但无济于事。 我使用的是 cakephp 2.x,但我认为这在这种情况下没有任何特别的意义(也许有?!)。 我正在使用 mandrill 在 https://bitbucket.org/mailchimp/mandrill-api-php 维护的 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 尚未附加。 我还尝试将路径直接添加到文件中,如下所示:
"attachments" => array(
array(
'type' => "application/pdf",
'name' => WWW_ROOT.'files/downloads/renewals/document.pdf',
)
我用谷歌搜索并阅读了我能找到的每篇文章,但找不到任何关于我应该如何指定山魈的路径以正确附加我的附件的具体引用。
任何帮助将不胜感激。
最佳答案
好的。所以感谢凯特琳的投入。 处理此问题的 PHP 方法是获取文件,然后对其进行 base64_encode:
$attachment = file_get_contents(WWW_ROOT.'files/downloads/file.pdf');
$attachment_encoded = base64_encode($attachment);
然后在 mandrill 数组的附件部分传递:
"attachments" => array(
array(
'content' => $attachment_encoded,
'type' => "application/pdf",
'name' => 'file.pdf',
)
很简单!再次感谢凯特琳!
关于php - Mandrill 电子邮件附件文件路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15213151/