Yii2 Email 如何设置发件人姓名

问题描述:

我使用 Mailer 发送电子邮件,所以我对发件人姓名有疑问这是我的配置

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' => ['admin@app.com' => 'App Sender Name'],
        ],
        'transport' => [
            'class' => 'Swift_MailTransport',
        ],
    ],

所以这是行不通的.我转到收件箱,只显示电子邮件.

So it's not work. I goto inbox and only email showed.

我需要显示为例子:

当我更新 setFrom() 方法时它的工作.例如:$mailer->setFrom(['email@app.com' => 'App Name']).这里是配置 Yii2 以通过 PHP 邮件和发件人名称发送

it's work when i update setFrom() method. Ex: $mailer->setFrom(['email@app.com' => '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' => ['admin@app.com' => 'App Sender Name'],
        ],
        'transport' => [
            'class' => 'Swift_MailTransport',
        ],
    ],

并发送电子邮件

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