dungphanxuan
dungphanxuan

Reputation: 615

Yii2 Email How to set sender name

i using Mailer to send email, so i have problem about sender name This is my config

    'mailer' => [
        'class' => 'yii\swiftmailer\Mailer',
        'useFileTransport' => false,
        'messageConfig' => [
            'charset' => 'UTF-8',
            'from' => ['[email protected]' => 'App Sender Name'],
        ],
        'transport' => [
            'class' => 'Swift_MailTransport',
        ],
    ],

So it's not work. I goto inbox and only email showed. enter image description here

And i need show as Example: enter image description here

Upvotes: 5

Views: 5429

Answers (2)

dungphanxuan
dungphanxuan

Reputation: 615

it's work when i update setFrom() method. Ex: $mailer->setFrom(['[email protected]' => 'App Name']). And here is config Yii2 for send by PHP mail and with sender name

'mailer' => [
        'class' => 'yii\swiftmailer\Mailer',
        'useFileTransport' => false,
        'messageConfig' => [
            'charset' => 'UTF-8',
            'from' => ['[email protected]' => 'App Sender Name'],
        ],
        'transport' => [
            'class' => 'Swift_MailTransport',
        ],
    ],

and send email

   Yii::$app->mailer->compose()
    ->setTo('[email protected]')
    ->setFrom(['[email protected]' => 'App Name'])
    ....

Upvotes: 9

ThangTD
ThangTD

Reputation: 1684

Every component and sub-component in yii2 is configurable by dependency injection, this case is same, eg:

        'transport' => [
            'class' => 'Swift_SmtpTransport',
            'host' => 'smtp.gmail.com',
            'username' => '[email protected]',
            'password' => '123456',
            'port' => '465',
            'encryption' => 'ssl',
        ],

Upvotes: 0

Related Questions