我想发送带附件的批量邮件。我可以通过将相同的文件附加到所有电子邮件来发送批量电子邮件。但是我需要通过在收件人变量中添加文件路径来将不同的文件附加到不同的电子邮件。我在 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/