PHP code example of lukasss93 / laravel-extra-mailable

1. Go to this page and download the library: Download lukasss93/laravel-extra-mailable 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/ */

    

lukasss93 / laravel-extra-mailable example snippets




namespace App\Mail;

use Illuminate\Mail\Mailable;
use Lukasss93\ExtraMailable\ExtraMailable;

class MyMail extends Mailable
{
    use ExtraMailable;

    protected int $value;

    public function __construct(int $value = 0)
    {
        $this->value = $value;
    }

    public function build() 
    {
        return $this->markdown('emails.myview', ['myvalue' => $this->value]);
    }
}



use App\Mail\MyMail;

// send mail to recipient (string)
MyMail::create()->sendTo('[email protected]');

// send mail to recipients (string with semicolon separator)
MyMail::create()->sendTo('[email protected];[email protected]');

// send mail to recipients (array)
MyMail::create()->sendTo(['[email protected]','[email protected]']);

// send mail to recipients (User)
MyMail::create()->sendTo(User::first());

// send mail to recipients (User collection)
MyMail::create()->sendTo(User::all());

// you can pass parameters in the create method
MyMail::create(69)->sendTo('[email protected]');

// send mail to recipients when condition is true
MyMail::create()->sendToWhen(true, '[email protected]');

// execute custom code when there is no recipients
MyMail::create()
    ->onEmptyRecipients(fn() => print('No emails sent! No recipient found.'))
    ->sendTo([]);
    
// execute custom code before sending emails
MyMail::create()
    ->onBeforeSendingMails(fn() => print('This message will be printed before sending emails'))
    ->sendTo('[email protected]');

// execute custom code after sending emails
MyMail::create()
    ->onAfterSendingMails(fn() => print('This message will be printed after sending emails'))
    ->sendTo('[email protected]');