PHP code example of wscore / mail

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

    

wscore / mail example snippets


use WScore\Mail\Transport\Transport;
use WScore\Mail\Mailer;

// 1. create a transport
$transport = Transport::forgeSmtp();

// 2. create a mailer
$mailer = Mailer::newInstance($transport);

// 3. send mails
$mailer->sendText('hello world', function(Swift_Message $message) {
    $message->setTo('[email protected]', 'tested');
});

// somewhere in a config file. 
use WScore\Mail\MessageDefault;
$default = MessageDefault::newInstance()
    ->withFrom('[email protected]', 'from address');
    ->withReturnPath('[email protected]')
    ->withReplyTo('[email protected]', 'sender name');

$mailer = Mailer::newInstance($transport)
    ->setMessageDefault($default);

// later on...
$mailer->setMessageDefault(
    $mailer->getMessageDefault()->withBulk() // send bulk mail?
);
$mailer->sendHtml('<h1>hi</h1>', function(Swift_Message $message) {
    $message->setTo('[email protected]');
});

Transport::goJapaneseIso2022();
$transport = Transport::forgeSmtp();
$mailer = Mailer::newInstance($transport);
$mailer->sendJIS('some japanese text here',
    function(Swift_Message $message) {
        $message->setTo('[email protected]', 'tested');
});