1. Go to this page and download the library: Download mattstein/usesend-laravel library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use Illuminate\Mail\Mailable;
use MattStein\UseSend\Concerns\HasUseSendTemplate;
class WelcomeMail extends Mailable
{
use HasUseSendTemplate;
public function build(): self
{
return $this->from('[email protected]')
->to($this->user)
->useSendTemplate('welcome_template', [
'name' => $this->user->name,
'attempts' => $this->user->attempts, // cast to a string for you
]);
}
}
use Illuminate\Mail\Mailable;
use MattStein\UseSend\Concerns\HasUseSendSchedule;
class MeetupReminder extends Mailable
{
use HasUseSendSchedule;
public function build(): self
{
return $this->subject('Your meetup is tomorrow')
->view('mail.reminder')
->useSendScheduledAt($this->meetup->starts_at->subDay());
}
}
use MattStein\UseSend\UseSendTransport;
$this->withSymfonyMessage(function (Email $email) use ($ticket): void {
$email->getHeaders()->addTextHeader(UseSendTransport::IN_REPLY_TO_ID_HEADER, $ticket->usesend_email_id);
});
use Illuminate\Mail\Mailable;
use MattStein\UseSend\Concerns\HasUseSendIdempotencyKey;
class OrderConfirmation extends Mailable
{
use HasUseSendIdempotencyKey;
public function build(): self
{
return $this->to($this->order->customer)
->subject('Your order')
->view('mail.order')
->useSendIdempotencyKey('order-confirmation-'.$this->order->id);
}
}
use Illuminate\Mail\Mailables\Headers;
use MattStein\UseSend\UseSendTransport;
public function headers(): Headers
{
return new Headers(text: [
UseSendTransport::IDEMPOTENCY_KEY_HEADER => 'order-confirmation-'.$this->order->id,
]);
}
use Illuminate\Mail\Events\MessageSent;
use MattStein\UseSend\UseSendTransport;
Event::listen(function (MessageSent $event) {
$emailId = $event->message->getHeaders()
->get(UseSendTransport::EMAIL_ID_HEADER)?->getBodyAsString();
});
Mail::to($user)->send(new InviteMail($user)); // with this on the mailable
$this->withSymfonyMessage(function (Email $email): void {
$email->getHeaders()->addTextHeader('X-Campaign', 'spring-invite');
$email->getHeaders()->addTextHeader('List-Unsubscribe', '<mailto:[email protected]>');
});
use Illuminate\Http\Client\Factory;
use MattStein\UseSend\UseSendTransport;
$http = (new Factory)->fake();
(new UseSendTransport(['api_key' => 'us_test_key'], $http))->send($email);
$http->assertSentCount(1);
bash
php artisan usesend:install
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.