Browse Source

feat(mail): Sendgrid 添加发件人名称 (#911)

clatteringmarion 5 years ago
parent
commit
7eb7549ec2
2 changed files with 7 additions and 3 deletions
  1. 2 1
      config/.config.example.php
  2. 5 2
      src/Services/Mail/SendGrid.php

+ 2 - 1
config/.config.example.php

@@ -48,7 +48,8 @@ $_ENV['smtp_ssl'] = true;
 
 # sendgrid
 $_ENV['sendgrid_key'] = '';
-$_ENV['sendgrid_sender'] = '';
+$_ENV['sendgrid_sender'] = '';     //发件邮箱
+$_ENV['sendgrid_name'] = '';       //发件人名称
 
 
 //备份设置--------------------------------------------------------------------------------------------

+ 5 - 2
src/Services/Mail/SendGrid.php

@@ -13,25 +13,28 @@ class SendGrid extends Base
     private $config;
     private $sg;
     private $sender;
+    private $name;
 
     public function __construct()
     {
         $this->config = $this->getConfig();
         $this->sg = new \SendGrid($this->config['key']);
         $this->sender = $this->config['sender'];
+        $this->name = $this->config['name'];
     }
 
     public function getConfig()
     {
         return [
             'key' => Config::get('sendgrid_key'),
-            'sender' => Config::get('sendgrid_sender')
+            'sender' => Config::get('sendgrid_sender'),
+            'name' => Config::get('sendgrid_name')
         ];
     }
 
     public function send($to_address, $subject_raw, $text, $files)
     {
-        $from = new Email(null, $this->sender);
+        $from = new Email($this->name, $this->sender);
         $subject = $subject_raw;
         $to = new Email(null, $to_address);
         $content = new Content('text/html', $text);