PHP code example of pendable / laravel-mailer

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

    

pendable / laravel-mailer example snippets


Mail::to('[email protected]')->send(new MyMailable);


// Laravel mailable instance
$mailable = new MyMailable;

// adding tags
$mailable->tag('my-tag-1');
$mailable->tag('my-tag-2');

// adding custom fields
$mailable->metadata('custom_1', 'one');
$mailable->metadata('custom_2', 'two');

$mailable->withSymfonyMessage(function(Email $message){

    // set the priority
    $message->getHeaders()->addTextHeader('priority', 60);

    // set the config identifier
    $message->getHeaders()->addTextHeader('config_identifier', 'my-config');

    // set the client email id (usually your system's unique identifier)
    $message->getHeaders()->addTextHeader('client_email_id', '1');

    // set the schedule send at (in ISO 8601 format)
    $message->getHeaders()->addTextHeader('schedule_send_at', '2023-06-25T22:37:26+05:30');
});


// send the mail
Mail::to('[email protected]')->send($mailable);



use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Headers;
use Illuminate\Queue\SerializesModels;
use Illuminate\Mail\Mailables\Envelope;

class MyMailable extends Mailable {

    use Queueable, SerializesModels;

    public function headers(): Headers
    {
        return new Headers(
            text: [
                // set the priority
                'priority' => '60',
                
                // set the config identifier
                'config_identifier' => 'my-config',
                
                // set the client email id (usually your system's unique identifier)
                'client_email_id' => '1',
                
                // set the schedule send at (in ISO 8601 format)
                'schedule_send_at' => '2023-06-25T22:37:26+05:30',
            ],
        );
    }

    /**
     * Get the message envelope.
     */
    public function envelope(): Envelope
    {
        return new Envelope(
            subject: 'My Mailer from Laravel + Pendable',
            
            // Setting tags
            tags: ['test', 'mailer', 'laravel'],
            
            // Setting custom fields
            metadata: [
                'custom_1' => 'one',
                'custom_2' => 'two',
            ],
        );
    }
    
    // ... 
}

# To send the mail
Mail::to('[email protected]')->send(new MyMailable);