To add attachments to Mailgun using Laravel, follow these steps:
composer require mailgun/mailgun-php:^3.0
config/services.php
file:'mailgun' => [
'domain' => env('MAILGUN_DOMAIN'),
'secret' => env('MAILGUN_SECRET'),
],
MAIL_MAILER
and MAIL_FROM_ADDRESS
variables to your .env
file:MAIL_MAILER=mailgun
MAIL_FROM_ADDRESS=me@example.com
MAILGUN_DOMAIN=your-domain-name
MAILGUN_SECRET=your-secret-key
use Mailgun\Mailgun;
$mgClient = new Mailgun(config('services.mailgun.secret'));
$domain = config('services.mailgun.domain');
$mgClient->messages()->send($domain, [
'from' => 'sender@example.com',
'to' => 'recipient@example.com',
'subject' => 'Your Subject',
'html' => '<h1>Mailgun HTML email with attachments</h1>',
'attachment' => [
[
'filePath' => '/path/to/attachment1.txt',
'filename' => 'attachment1.txt'
],
[
'filePath' => '/path/to/attachment2.pdf',
'filename' => 'attachment2.pdf'
]
]
]);
In this example, we used the Mailgun API client to send an email with two attachments: attachment1.txt
and attachment2.pdf
. The attachments are specified using their file paths and filenames.
That's it! You can now send emails with attachments using Mailgun in Laravel.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2021-06-19 11:00:00 +0000
Seen: 7 times
Last updated: Feb 01
How can a HTTP header be inserted in WordPress?
How can data be stored in a data attribute and utilized through Ajax?
How can an array be passed using typo3 flexform xml and itemsProcConfig?
Does JSON encode fail to retrieve data from the database?
Can the GS1 128 barcode decoder in PHP or Jquery be utilized?
How can Xdebug be used in conjunction with VSCode for Laravel on Sail and WSL2?
In PHP, what is the method for finding encrypted data using the "like" operator?
What is the method to pass a variable from PHP back to JavaScript?
Why do PHP variable variables display unexpected behavior when used with arrays?