0

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);
  • What API version are you using? The examples under https://documentation.mailgun.com/en/latest/api-sending.html#examples all look slightly different, regarding the instantiation of the MailGun client, and how the send method is called. – CBroe Jan 20 '23 at 07:35
  • @CBroe I'm using version 01.0. Probably an older version. – christian nyembo Jan 20 '23 at 08:31

1 Answers1

0

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

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