PHP code example of camelmailer / camelmailer-laravel
1. Go to this page and download the library: Download camelmailer/camelmailer-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/ */
camelmailer / camelmailer-laravel example snippets
use App\Mail\OrderShipped;
use Illuminate\Support\Facades\Mail;
Mail::to('[email protected]')->send(new OrderShipped($order));
class OrderShipped extends Mailable
{
public function __construct(public Order $order) {}
public function envelope(): Envelope
{
return new Envelope(subject: 'Your order has shipped');
}
public function content(): Content
{
return new Content(view: 'emails.orders.shipped');
}
}
use Illuminate\Notifications\Notification;
use Illuminate\Notifications\Messages\MailMessage;
class InvoicePaid extends Notification
{
public function via(object $notifiable): array
{
return ['mail'];
}
public function toMail(object $notifiable): MailMessage
{
return (new MailMessage)
->subject('Invoice paid')
->line('Your invoice has been paid. Thank you!');
}
}
$user->notify(new InvoicePaid);
// A campaign is content plus an audience. The two ways to create one
// behave differently: createDraft() writes it and waits, createAndSend()
// expands it to the stream's subscribers before the call returns.
CamelMailer::campaigns()->createDraft([
'stream' => 'newsletter',
'from' => '[email protected]',
'name' => 'September',
'subject' => 'What shipped',
'text_body' => 'Hello.',
]);
CamelMailer::campaigns()->createAndSend('newsletter', [
'name' => 'Status update',
'from' => '[email protected]',
'text_body' => 'All clear.',
]);
// A broadcast send to an address that is not subscribed is refused, so
// this list is the audience.
CamelMailer::subscribers()->add('newsletter', ['address' => '[email protected]']);
CamelMailer::subscribers()->import('newsletter', ['[email protected]', '[email protected]']);
CamelMailer::layouts()->list();
CamelMailer::inbound()->list(['status' => 'held']);
CamelMailer::logs()->tags();