PHP code example of jerowork / email-message

1. Go to this page and download the library: Download jerowork/email-message 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/ */

    

jerowork / email-message example snippets


// Construct message
$message = new Message(
    Addressee::fromString('Jero Work <[email protected]'),
    'Some subject',
    new Body('<p>Some html body</p>')
);

// Add to recipients
$message = $message
    ->withToRecipient(
        Addressee::fromString('[email protected]'),
        Addressee::fromString('[email protected]')
    );

// Add cc/bcc recipients
$message = $message
    ->withCcRecipient(Addressee::fromString('Somebody <[email protected]>'))
    ->withBccRecipient(new Addressee(new Email('[email protected]'), 'Another body'));

// Add reply to email
$message = $message->withReplyToEmail(new Email('[email protected]'));

// Add attachments
$message = $message->withAttachment(
    '/path/to/file',
    '/path/to/file'
);

// Update body
$message = $message->withTextBody('Some text body');

// Update other parameters, e.g. sender
$message = $message->withSender(Addressee::fromString('[email protected]'));

// Verify if email is setup correctly
if ($message->isValid() === true) {
    // Do something
    // ...
    $subject      = $messsage->getSubject();
    $toRecipients = $message->getToRecipients();
}

// Serialize value object (for use in e.g. queues)
$array = $message->jsonSerialize();