簡體   English   中英

如何使用Mailgun發送帶有附件的批量/批量電子郵件?

[英]How to send batch/mass emails with attachments using 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%')
    ));    

上面的代碼不起作用。 附件數組無法使用收件人變量。 /path/to/file替換%recipient.image%可以正常工作。

根據與Mailgun支持團隊的交談,目前,Mailgun還無法為每個收件人分配特定的附件。 可以嘗試的一件事是在服務器上提供文件並為用戶分配URL以從中檢索文件(僅在文件不是機密文件並永久存儲在服務器上的情況下才建議這樣做)。

文檔

'attachment'=> [['fileContent'=> $ binaryFile,'filename'=>'test.jpg']]

要么

'attachment'=> [[['filePath'=>'/ tmp / foo.jpg','filename'=>'test.jpg']]

或(內聯):

'inline'=> [[['filePath'=>'/ tmp / foo.jpg','filename'=>'test.jpg']]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM