PHP code example of zazymko / yii-swiftmailer
1. Go to this page and download the library: Download zazymko/yii-swiftmailer 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/ */
zazymko / yii-swiftmailer example snippets
return [
//....
'components' => [
'mailer' => [
'class' => 'zazymko\swiftmailer\swift\Mailer',
],
],
];
return [
//....
'components' => [
'mailer' => [
'class' => 'zazymko\swiftmailer\swift\Mailer',
//'viewPath' => 'application.mail' //default path to views
'transport' => [
'host' => 'smtp.example.ru.',
'username' => 'username',
'password' => 'password',
'port' => '465',
'encryption' => 'ssl',
],
'messageConfig' => [
'from' => ['[email protected] ' => 'Example Name']
]
],
],
];
return [
//....
'components' => [
'debug' => [
'class' => 'application.vendor.zhuravljov.yii2-debug.Yii2Debug',
'enabled' => YII_DEBUG,
'panels' =>[
'mail' => [
'class' => 'zazymko\swiftmailer\debug\MailPanel'
]
],
],
],
];
Yii::app()->mailer->compose()
->setFrom('[email protected] ')
->setTo('[email protected] ')
->setSubject('Message subject')
->setTextBody('Plain text content')
->setHtmlBody('<b>HTML content</b>')
->send();
$messages = [];
foreach ($users as $user) {
$messages[] = Yii::app()->mailer->compose()
// ...
->setTo($user->email);
}
Yii::$app->mailer->sendMultiple($messages);
/* @var $this \zazymko\swiftmailer\View */
/* @var $message \zazymko\swiftmailer\MessageInterface */
/* @var $content string main view render result */
/* @var $this \zazymko\swiftmailer\View */
/* @var $message \zazymko\swiftmailer\MessageInterface */
Yii::app()->mailer->compose('test', ['model'=>User::model()->findByPk(1)])
->setFrom('[email protected] ')
->setTo('[email protected] ')
->setSubject('Message subject')
->send();
$message = Yii::app()->mailer->compose();
// Attach file from local file system:
$message->attach('/path/to/source/file.pdf');
// Create attachment on-the-fly
$message->attachContent('Attachment content', ['fileName' => 'attach.txt', 'contentType' => 'text/plain']);
Yii::app()->mailer->compose('embed-email', ['imageFileName' => '/path/to/image.jpg'])
// ...
->send();
<img src="<?= $message->embed($imageFileName);