PHP code example of sugarcraft / sugar-post

1. Go to this page and download the library: Download sugarcraft/sugar-post 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/ */

    

sugarcraft / sugar-post example snippets


use SugarCraft\Post\{Email, Mailer, ResendTransport};

$transport = new ResendTransport('re_xxxxxxxxxxxxx');
$mailer = new Mailer($transport);

$email = new Email(
    from:    '[email protected]',
    to:      ['[email protected]'],
    subject: 'Hello from SugarPost',
    body:    'Sent via the Resend API.',
);

$mailer->send($email);

use SugarCraft\Post\{Email, Mailer, SmtpTransport};

$transport = new SmtpTransport('smtp.gmail.com', 587, 'username', 'password');
$mailer = new Mailer($transport);

$mailer->send(new Email(
    from:    '[email protected]',
    to:      ['[email protected]'],
    subject: 'Hello via SMTP',
    body:    'Sent directly via SMTP.',
));

$email = new Email(/* ... */);
$email = $email->withAttachment('invoice.pdf', '/path/to/invoice.pdf');
$mailer->send($email);