christian nyembo
christian nyembo

Reputation: 135

How to add attachment to mailgun API using PHP

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);

Upvotes: 0

Views: 187

Answers (1)

christian nyembo
christian nyembo

Reputation: 135

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

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

Upvotes: 0

Related Questions