php - 如何使用 mailgun 批量发送带附件的邮件?

标签 php laravel email email-attachments mailgun

我想发送带附件的批量邮件。我可以通过将相同的文件附加到所有电子邮件来发送批量电子邮件。但是我需要通过在收件人变量中添加文件路径来将不同的文件附加到不同的电子邮件。我在 mailgun 的官方文档中看不到任何相关内容。

这是我的代码:

 # Instantiate the client.
    $mgClient = new Mailgun('key-****');
    $domain = "foo.bar.com";

    # Make the call to the client.
    $result = $mgClient->sendMessage($domain, array(
        'from'    => 'gido@foo.baar.com',
        'to'      => array('user1@gmail.com', 'user2@gmail.com'),
        'subject' => 'Hi %recipient.first%',
        'text'    => 'Hey there, Just Testing',
        'recipient-variables' => '{"user1@gmail.com": {"first":"User1", "id":1, "file" : "/path/to/file1"},
                                   "user2@gmail.com": {"first":"User2", "id": 2, "file" : "/path/to/file2"}}'
    ), array(
        'attachment' => array('%recipient.file%')
    ));    

上面的代码不起作用。附件数组无法使用收件人变量。将 %recipient.image% 替换为 /path/to/file 效果很好。

最佳答案

根据与 Mailgun 支持团队的对话,目前 Mailgun 无法为每个收件人分配特定的附件。可以尝试的一件事是在服务器上提供文件并为用户分配一个 URL 以从中检索文件(仅在文件不 secret 且永久存储在服务器上的情况下才建议这样做。)。

关于php - 如何使用 mailgun 批量发送带附件的邮件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53700989/

相关文章:

php - CompilerPass 的 Symfony2 解释?

javascript - nodemailer 登录无效 : 535 Authentication Failed

matlab - 通过 MATLAB 发送电子邮件

redis 中的 PHP session 不起作用

php - 使用 PHP 为带有 .pfx 证书的 XML 文件签名

php - 覆盖模型的软删除表列

Laravel 护照 : Authenticate api requests based on access token issued by another microservice

php - Laravel:选择数据库错误 undefined index 或尝试获取非对象的属性

html - ColdFusion If 语句导致 <cfmail> 中出现空格

javascript - 如何使用 jQuery Ajax.Request 将多个变量类型传递给 php