Sendcloud driver installation tutorial for laravel 5.1

Time:2021-4-14

advantage:
The normal sending mode is fully compatible with the official usage, and the configuration file can be changed to other drivers at any time without changing the code

install
Execute in the project directory

composer require naux/sendcloud
to configure
Modify config/ app.php

‘providers’ => [
//Add this line
Naux\Mail\ SendCloudServiceProvider::class,
];
Configure your key in. Env and modify the email driver to sendcloud

MAIL_DRIVER=sendcloud

SEND_ CLOUD_ User = # created API_ user
SEND_ CLOUD_ Key = # assigned API_ key
use
Normal sending:
The usage is exactly the same as that of the system. Please refer to the official document for detailslearnku.com/docs/laravel/5.1/mail

Mail::send(‘emails.welcome’, $data, function ($message) {
$message->from(‘[email protected]‘, ‘Laravel’);

$message->to('[email protected]')->cc('[email protected]');

});
Template sending
The usage is similar to ordinary sending, but you need to set the body as the sendcloudtemplate object. There are several ways to achieve this

First usage:
Mail:: send (‘Send an empty view ‘, [], function ($message){
$message->from(‘[email protected]‘, ‘Laravel’);

$message->to('[email protected]')->cc('[email protected]');

//Template variables
$bind_data = ['url' => 'http://naux.me'];
$template = new sendcloudtemplate ('template name ', $bind_ data);

$message->getSwiftMessage()->setBody($template);

});
Second usage:
//Template variables
$bind_data = [‘url’ => ‘http://naux.me’];
$template = new sendcloudtemplate (‘template name ‘, $bind’)_ data);

Mail::raw($template, function ($message) {
$message->from(‘[email protected]‘, ‘Laravel’);

$message->to('[email protected]')->cc('[email protected]');

});

————————————————
Original author: naux Liu
From link:Tutorial: sendcloud driver for laravel 5.1
Copyright notice: the copyright belongs to the author. For commercial reprint, please contact the author for authorization. For non-commercial reprint, please keep the above author information and original link.

This work adoptsCC agreementReprint must indicate the author and the link of this article