1. Go to this page and download the library: Download vancil/flint-mail 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/ */
namespace App\Mail;
use Vancil\FlintMail\Mailable;
class WelcomeEmail extends Mailable
{
public function __construct(private User $user) {}
public function build(): void
{
$this->to($this->user->email, $this->user->name)
->subject('Welcome to ' . config('app.name'))
->view('emails.welcome', ['user' => $this->user]);
}
}
// Synchronous — sends immediately
(new WelcomeEmail($user))->send();
// Queued — dispatched to Flint's queue worker
(new WelcomeEmail($user))->queue();
(new WelcomeEmail($user))->queue('emails'); // named queue
$this->to('[email protected]', 'User') // recipient
->from('[email protected]', 'Sender') // override default from
->replyTo('[email protected]')
->subject('Hello')
->cc('[email protected]', 'Manager')
->cc('[email protected]')
->bcc('[email protected]')
->html('<p>Hello <b>world</b></p>') // raw HTML body
->text('Hello world') // plain text fallback
->view('emails.welcome', ['user' => $u]) // Spark template as HTML
->attach('/path/to/file.pdf', 'Invoice.pdf', 'application/pdf');
use Vancil\FlintMail\Mailer;
class NotificationController
{
public function __construct(private readonly Mailer $mailer) {}
public function notify(Request $request): Response
{
$this->mailer
->to('[email protected]', 'User')
->subject('New notification')
->html('<p>You have a new message.</p>')
->cc('[email protected]')
->send();
// Or queue it:
$this->mailer
->to('[email protected]')
->subject('Report')
->attach('/tmp/report.pdf', 'Monthly Report.pdf')
->queue('reports');
return Response::redirect('/');
}
}