Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Yii2 Email How to set sender name

Tags:

yii2

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

like image 563
dungphanxuan Avatar asked Aug 30 '16 03:08

dungphanxuan


1 Answers

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'])
    ....
like image 86
dungphanxuan Avatar answered Oct 17 '22 09:10

dungphanxuan