我使用Mailer发送电子邮件,所以我有关于发件人姓名的问题这是我的配置
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'useFileTransport' => false,
'messageConfig' => [
'charset' => 'UTF-8',
'from' => ['admin@app.com' => 'App Sender Name'],
],
'transport' => [
'class' => 'Swift_MailTransport',
],
],
Run Code Online (Sandbox Code Playgroud)
它更新setFrom()方法时工作.例如:$ mailer-> setFrom(['email@app.com'=>'App Name']).这里是配置Yii2,用于通过PHP邮件和发件人名称发送
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'useFileTransport' => false,
'messageConfig' => [
'charset' => 'UTF-8',
'from' => ['admin@app.com' => 'App Sender Name'],
],
'transport' => [
'class' => 'Swift_MailTransport',
],
],
Run Code Online (Sandbox Code Playgroud)
并发送电子邮件
Yii::$app->mailer->compose()
->setTo('client@email.com')
->setFrom(['admin@app.com' => 'App Name'])
....
Run Code Online (Sandbox Code Playgroud)
yii2 中的每个组件和子组件都可以通过依赖注入进行配置,这种情况是相同的,例如:
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.gmail.com',
'username' => 'noreply.yourcompany@gmail.com',
'password' => '123456',
'port' => '465',
'encryption' => 'ssl',
],
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3220 次 |
| 最近记录: |