PHP code example of webiik / mail

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

    

webiik / mail example snippets


$mail = new \Webiik\Mail\Mail();

// Add PHPMailer
$mail->setMailer(function () {
    return new \Webiik\Mail\Mailer\PHPMailer(new \PHPMailer\PHPMailer\PHPMailer());
});

// Create Message
$message = $mail->createMessage();

// Set charset and priority of Message
$message->setCharset('utf-8');
$message->setPriority(3);

// Set Message sender, bounce address and recipients
$message->setFrom('[email protected]', 'Firstname Lastname');
$message->setBounceAddress('[email protected]');
$message->addTo('[email protected]', 'Firstname Lastname');
$message->addReplyTo('[email protected]');
$message->addCc('[email protected]');
$message->addBcc('[email protected]');

// Set Message subject and body
$message->setSubject('Test subject');
$message->setBody('Hello world, this is body of test message.');
$message->setAlternativeBody('Hellow world, this is alternative body of test message.');

// Set Message attachment
$message->addFileAttachment(__DIR__ . '/nice_picture.jpg');

// Send Message
$unsent = $mail->send([$message]);

// Get unsent email addresses
foreach ($unsent as $email) {
    // Do something with undelivered email
}

setMailer(callable $factory):void

$mail->setMailer(function () {
    return new \Webiik\Mail\Mailer\PHPMailer(new \PHPMailer\PHPMailer\PHPMailer());
});

// CustomMailer.php
declare(strict_types=1);

namespace Webiik\Mail\Mailer;

use Webiik\Mail\Message;

class CustomMailer implements MailerInterface
{
    // Your implementation...

getMailerCore()

$phpMailer = $mail->getMailerCore(); 

send(array $messages): array

$mail->send($messages); 

createMessage(): Message

$message = $mail->createMessage();

setCharset(string $charset): void

getCharset(): string

setPriority(int $int): void

getPriority(): int

setFrom(string $email, string $name = ''): void

getFrom(): array

setBounceAddress(string $email): void

getBounceAddress(): string

addTo(string $email, string $name = ''): void

getTo(): array

addReplyTo(string $email, string $name = ''): void

getReplyTo(): array

addCc(string $email, string $name = ''): void

getCc(): array

addBcc(string $email, string $name = ''): void

getBcc(): array

setSubject(string $subject): void

getSubject(): string

setBody(string $string, $mime = 'text/html'): void

getBody(): array

setAlternativeBody(string $string): void

getAlternativeBody(): string

addFileAttachment(string $path, string $filename = '', string $mime = ''): void

getFileAttachments(): array

addDynamicAttachment(string $string, string $filename, string $mime = ''): void

getDynamicAttachments(): array

addFileEmbed(string $path, string $cid, string $filename = '', string $mime = ''): void

getFileEmbeds(): array

addDynamicEmbed(string $string, string $cid, string $filename = '', string $mime = ''): void

getDynamicEmbeds(): array