1. Go to this page and download the library: Download yiisoft/yii2-symfonymailer 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/ */
yiisoft / yii2-symfonymailer example snippets
return [
//....
'components' => [
'mailer' => [
'class' => \yii\symfonymailer\Mailer::class,
'transport' => [
'scheme' => 'smtps',
'host' => '',
'username' => '',
'password' => '',
'port' => 465,
'dsn' => 'native://default',
],
'viewPath' => '@common/mail',
// send all mails to a file by default. You have to set
// 'useFileTransport' to false and configure transport
// for the mailer to send real emails.
'useFileTransport' => false,
],
],
];
namespace app\utils;
use Symfony\Component\Mailer\Transport\Dsn;
use Symfony\Component\Mailer\Transport\Smtp\SmtpTransport;
use Symfony\Component\Mailer\Transport\TransportFactoryInterface;
use Symfony\Component\Mailer\Transport\TransportInterface;
use yii\base\BaseObject;
final class CustomSmtpFactory extends BaseObject implements TransportFactoryInterface
{
public float $timeout;
public function create(Dsn $dsn): TransportInterface
{
$transport = $this->create($dsn);
if ($transport instanceof SmtpTransport) {
/** @var SocketStream $stream */
$stream = $transport->getStream();
$stream->setTimeout($this->timeout);
}
return $transport;
}
public function supports(Dsn $dsn): bool
{
return $dsn->getScheme() == 'smtp';
}
}
'container' => [
'definitions' => [
EsmtpTransportFactory::class => [
'class' => \app\utils\CustomSmtpFactory::class,
'timeout' => 143, //Configure it to your own timeout
],
// ... other definitions
],
],
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.