PHP code example of pollen-solutions / mail

1. Go to this page and download the library: Download pollen-solutions/mail 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/ */

    

pollen-solutions / mail example snippets


use Pollen\Mail\MailManager;

$mail = new MailManager();

$mail->send([
    'to'   => ['[email protected]', 'Recipient Name'],
    'from' => ['[email protected]', 'Sender Name'],
]);

use Pollen\Mail\MailManager;

$mail = new MailManager();

$mail->debug([
    'to'   => ['[email protected]', 'Recipient Name'],
    'from' => ['[email protected]', 'Sender Name']
]);

/**
 * Name identifier in mail manager.
 * @var string|null
 */
'name'         => null,
/**
 * Recipients of the message.
 * @var string|array|null
 */
'to'           => null,
/**
 * Message sender.
 * @var string|array|null
 */
'from'         => null,
/**
 * Reply-to contact of the message.
 * @var string|array|null
 */
'reply-to'     => null,
/**
 * Blind carbon copy recipients of the message.
 * @var string|array|null
 */
'bcc'          => null,
/**
 * Carbon copy recipients of the message.
 * @var string|array|null
 */
'cc'           => null,
/**
 * Attachments of the message.
 * @var string|array|null
 */
'attachments'  => null,
/**
 * HTML content of the message.
 * {@internal false or empty to disable|true to use the html/message template|string of the HTML
 * content|array of message parts. The Array parts could have header|body|footer key and typed
 * as bool|string.}
 * @var bool|string|array|null
 */
'html'         => true,
/**
 * Plain text content of the message.
 * {@internal false or empty to disable|true to use the text/message template|string of text content.}
 * @var string|null
 */
'text'         => null,
/**
 * List of template datas.
 * @var array
 */
'datas'        => [],
/**
 * Subject of the message.
 * @var string
 */
'subject'      => 'Mail test',
/**
 * Locale of the message.
 * @var string
 */
'locale'       => 'en',
/**
 * Charset of the message.
 * @var string
 */
'charset'      => 'utf-8',
/**
 * Encoding of the message.
 * @var string|null 8bit|7bit|binary|base64|quoted-printable
 */
'encoding'     => null,
/**
 * Content type of the message.
 * @var string|null multipart/alternative|text/html|text/plain
 */
'content_type' => null,
/**
 * Css properties of the HTML message.
 * @var string
 */
'css'          => file_get_contents($this->mail()->resources('/assets/css/styles.css')),
/**
 * Inline CSS formatting flag.
 * @var bool
 */
'inline_css'   => true,
/**
 * List of parameters of the template view|View instance.
 * @var array|ViewInterface $view
 */
'view'         => [],

use Pollen\Mail\MailManager;

$mail = new MailManager();

$mail->setMailable([
    'name' => 'my-first-mail',
    'to'   => ['[email protected]', 'Recipient Name'],
    'from' => ['[email protected]', 'Sender Name'],
]);

if ($mailable = $mail->get('my-first-mail')) {
    $mailable->send();
}

use Pollen\Mail\MailManager;
use Pollen\Mail\Mailable;

$mail = new MailManager();
$mailable = new Mailable($mail);
$mailable
    ->setFrom(['[email protected]', 'Sender Name'])
    ->setTo(['[email protected]', 'Recipient Name']);

$mailable->send();

use Pollen\Mail\MailManager;
use Pollen\Mail\Mailable;

$mail = new MailManager();
$mailable = new class($mail) extends Mailable {
    protected ?array $from = ['[email protected]', 'Sender Name'];
    protected ?array $to = ['[email protected]', 'Recipient Name'];
};

$mailable->send();

use Pollen\Mail\MailManager;
use Pollen\Mail\Drivers\PhpMailerDriver;

$mail = new MailManager();
$mail->setMailerConfigCallback(function (PhpMailerDriver $mailer) {
    $mailer->isSMTP();
    $mailer->Host = '0.0.0.0';
    $mailer->Username = 'mailhog.example';
    $mailer->Port = 1025;
});

$mail->send();

# functions.php 
add_action('phpmailer_init', function (PHPMailer $mailer) {
    $mailer->isSMTP();
    $mailer->Host = '0.0.0.0';
    $mailer->Username = 'mailhog.example';
    $mailer->Port = 1025;
});