1

How do we add an attachment with mailgun ? Why can't I find how to do such a basic thing ? I've tried multiple recipes, and it never works.

For instance :

    $msg = $mg->MessageBuilder();
    $msg->setFromAddress($sender_email);
    $msg->addToRecipient($to);
    $msg->setSubject($subject);
    $msg->setTextBody($body);
    $msg->addAttachment('zzz.txt');
$files['attachment'] = array();
$files['attachment'][] = 'zzz.txt';

    $mg->post("{$domain}/messages", $msg->getMessage(), $files);

Why the file zzz.txt is not included in the email ?

Why is there absolutely no clear instructions anywhere about how to do this ?

trogne
  • 3,402
  • 3
  • 33
  • 50
  • RTM maybe? https://documentation.mailgun.com/api-sending.html – Funk Forty Niner Dec 28 '15 at 03:30
  • possible duplicate of http://stackoverflow.com/questions/14229656/mailgun-sent-mail-with-attachment – Funk Forty Niner Dec 28 '15 at 03:31
  • What do you say ? I'm not using curl ! – trogne Dec 28 '15 at 03:34
  • How to add an attachement in the same way as I add the subject or the body ? – trogne Dec 28 '15 at 03:35
  • addAttachment method should work, to make sure you have access to zzz.txt, use file_exists function to double check. – ‌‌R‌‌‌. Dec 28 '15 at 04:17
  • I have access to the file. What's missing in my code ? – trogne Dec 28 '15 at 15:31
  • Using both methods (sendmessage and MessageBuilder), I get this : Fatal error: Uncaught exception 'Guzzle\Http\Exception\CurlException' with message '[curl] 26: couldn't open file "zzz.txt" [url] https://api.mailgun.net/v2/sandbox8df78f0cdbc646aeb2a46999a8c6def5.mailgun.org/messages'; in C:\xampp\htdocs\tutlage\newsletter\vendor\guzzle\guzzle\src\Guzzle\Http\Curl\CurlMulti.php:359 Stack trace: #0 ......................... – trogne Dec 28 '15 at 15:56

0 Answers0