/yii2-symfonymailer

Yii 2 Symfony mailer extension.

Primary LanguagePHPBSD 3-Clause "New" or "Revised" LicenseBSD-3-Clause

Yii Mailer Library - Symfony Mailer Extension


This extension provides a Symfony Mailer mail solution for Yii framework 2.0.

For license information check the LICENSE-file.

Latest Stable Version Total Downloads Build Status

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist yiisoft/yii2-symfonymailer

or add

"yiisoft/yii2-symfonymailer": "~2.0.0"

to the require section of your composer.json.

Note: Version 2.0 of this extension uses Symfonymailer, which requires PHP 8.

Usage

To use this extension, simply add the following code in your application configuration:

return [
    //....
    'components' => [
        'mailer' => [
            'class' => \yii\symfonymailer\Mailer::class,            
            'transport' => [
                'scheme' => '',
                'host' => '',
                'username' => '',
                'password' => '',
                'port' => 465,
                'options' => ['ssl' => true],
            ],
        ],
    ],
];

You can then send an email as follows:

Yii::$app->mailer->compose('contact/html')
     ->setFrom('from@domain.com')
     ->setTo($form->email)
     ->setSubject($form->subject)
     ->send();