How to add attachment to mailgun API using PHP

74 Views Asked by At

I have been using the mailgun API to send emails in my PHP application, When I add the attachment parameter as per the documentation, I got an error:Invalid resource type: array in /var/www/html/vendor/guzzlehttp/psr7/src/functions.php

Can someone assist?

$mgClient = new Mailgun('xxx');
$domain = "xxx";
$parameters = array(
              'from'    => 'xxx',
              'to'      => $to,
              'subject' => $subject,
              'text'    => $text,
              'attachment' = [
                [
                  'filePath' => $attachment,
                  'filename' => $file_name,  
                ]
              ];
);

$result = @$mgClient->sendMessage("$domain", $parameters);
1

There are 1 best solutions below

0
christian nyembo On

I found a solution by adding the attachment array as a third parameter of the sendMessage()

$mgClient->sendMessage("$domain", $parameters, ['attachment' => ['filePath' => $file_path]]);