PHP code example of runner / gatling-mail

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

    

runner / gatling-mail example snippets


(new Email())->content(function(Message $message) {
    $message->setName('test message')
            ->setContent('test content by {username}')
            ->setParameters([
                'username' => 'runnerlee',
            ]);
});


(new Email())->content(function(Message $message) {
    $message->setName('test message')
            ->setContent('test content by %username%')
            ->setDelimiter('%', '%')
            ->setParameters([
                'username' => ['runnerlee'],
            ]);
});



// 实例化发送驱动,
$sendcloud = new \Runner\GatlingMail\Drivers\SendCloudDriver([
    'api_user' => 'shuai',
    'api_key'  => 'bi',
]);

// 实例化发送器, 装入发送驱动,
$mailer = new \Runner\GatlingMail\Mailer($sendcloud);

// 实例化邮件, 类似于用客户端发送邮件时的新建邮件动作
$email = (new \Runner\GatlingMail\Email())
            ->subject('this is a test email')
            ->to('[email protected]')
            ->from('[email protected]', '收水费了')
            ->content(function(\Runner\GatlingMail\Message $message) {
                $message->setName('test message')
                        ->setContent('test content by %username%')
                        ->setDelimiter('%', '%')
                        ->setParameters([
                            'username' => 'runnerlee',
                        ]);
            })
            ->tag('10086')
            ->attach('address.txt', __DIR__ . '/address.txt');

// 装入邮件, biubiubiu
$mailer->setEmail($email)->send();


public function registerService()
{
    // 配置发送驱动
    $sendCloud = new \Runner\GatlingMail\Drivers\SendCloudDriver([
        'api_user' => '',
        'api_key'  => '',
    ]);
    $email = (new \Runner\GatlingMail\Email())->from('[email protected]', 'runnerlee');
    return [
        'mailer' => (new \Runner\GatlingMail\Mailer($sendCloud)),
    ];
}


public function indexAction()
{
    $this->get('mailer')
         ->getEmail()
         ->to('[email protected]')
         ->content(function(\Runner\GatlingMail\Message $message) {
             $message->setName('test message')
                 ->setContent('test content by {username}')
                 ->setParameters([
                     'username' => 'runnerlee',
                 ]);
         })
         ->subject('this is a test email');

    $this->get('mailer')->send();
}