我使用Mailer发送电子邮件,所以我对发件人姓名有疑问 这是我的配置
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'useFileTransport' => false,
'messageConfig' => [
'charset' => 'UTF-8',
'from' => ['admin@app.com' => 'App Sender Name'],
],
'transport' => [
'class' => 'Swift_MailTransport',
],
],
答案 0 :(得分:5)
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',
],
],
and send email
Yii::$app->mailer->compose()
->setTo('client@email.com')
->setFrom(['admin@app.com' => 'App Name'])
....
答案 1 :(得分:0)
yii2中的每个组件和子组件都可以通过依赖注入进行配置,这种情况是相同的,例如:
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.gmail.com',
'username' => 'noreply.yourcompany@gmail.com',
'password' => '123456',
'port' => '465',
'encryption' => 'ssl',
],