Pārlūkot izejas kodu

会员注册:发送welcome邮件.

kevin 1 gadu atpakaļ
vecāks
revīzija
7fabc303ea

+ 13 - 1
common/config/main.php

@@ -57,7 +57,19 @@ return [
             // send all mails to a file by default. You have to set
             // 'useFileTransport' to false and configure a transport
             // for the mailer to send real emails.
-            'useFileTransport' => true,
+            'useFileTransport' => true, // true(缓存到文件中) false(发送邮件)
+            'transport' => [
+                'class' => 'Swift_SmtpTransport',
+                'host' => 'mail.authsmtp.com',
+                'port' => 325,
+                'username' => 'ac71555',
+                'password' => 'I1j-MKi-fJ8-nHb',
+                'encryption' => 'TLS',
+            ],
+            'messageConfig' => [
+                'charset' => 'UTF-8',
+                'from' => ['address' => 'eshop-noreply@elken.com']
+            ],
         ],
         'swooleAsyncTimer' => [
             'class' => 'common\components\SwooleAsyncTimer',

+ 2 - 2
common/config/params.php

@@ -1,8 +1,8 @@
 <?php
 $nationParams = require_once __DIR__ . '/params-nation.php';
 return [
-    'adminEmail' => 'admin@example.com',
-    'supportEmail' => 'support@example.com',
+    'adminEmail' => 'system@elken.com',
+    'supportEmail' => 'system@elken.com',
     'nation' => $nationParams,
     'backAccessTokenExpiresIn' => 3000 * 60,
     'backRefreshTokenExpiresIn' => 3000 * 60 * 60,

+ 33 - 0
common/helpers/Email.php

@@ -0,0 +1,33 @@
+<?php
+
+namespace common\helpers;
+
+use Yii;
+
+class Email
+{
+    /**
+     * @param string $email
+     * @param string $userName
+     * @param string $password
+     * @return bool
+     */
+    public static function sendRegistrationEmail(string $email, string $userName, string $password): bool
+    {
+        $subject = 'Elken Welcome You.';
+        $message = \Yii::t('ctx', 'welcomeEmail', ['userName' => $userName, 'passWord' => $password]);
+
+        $email = 'kevin@elken.com'; // TODO: test
+
+        $mailer = Yii::$app->mailer->compose();
+        $mailer->setFrom(Yii::$app->params['adminEmail']);
+        $mailer->setTo($email);
+        $mailer->setSubject($subject);
+        $mailer->setHtmlBody($message);
+        if ($mailer->send()) {
+            return true;
+        }
+
+        return false;
+    }
+}

+ 22 - 1
common/messages/en-US/app.php

@@ -308,5 +308,26 @@ return [
     'invalidParameter' => 'Invalid Parameter',
     'dataDoesNotExists' => 'The data does not exist',
 
-
+    # Email
+    'welcomeEmail' => "
+        CONGRATULATIONS!
+    
+        Congratulations on your successful registration into Elken Global system and family.
+        
+        We are committed to building you to build others
+        
+        Login to your back office using the link provided below
+        
+        https://ngds.elken.com/#/login?redirect=%2Fdashboard%2Findex#
+        
+        Username = {userName}
+        Password = {passWord}
+        
+        We recommend that you change your password to what you will easily remember.
+        
+        For further inquiries do not hesitate to contact +23480 3413 0554
+        
+        We are committed to ensuring that you succeed.
+        
+        Once again congratulations!",
 ];

+ 23 - 0
common/messages/zh-CN/app.php

@@ -314,4 +314,27 @@ return [
     'invalidParameter' => '无效参数',
     'dataDoesNotExists' => '数据不存在',
 
+    # Email
+    'welcomeEmail' => "
+        恭喜!
+
+        恭喜您成功注册到Elken Global系统和家庭。
+        
+        我们致力于打造你来打造他人
+        
+        使用下面提供的链接登录您的后台办公室
+        
+        https://ngds.elken.com/#/login?redirect=%2Fdashboard%2Findex#
+        
+        用户名 = {userName}
+        密 码 =  = {passWord}
+        
+        我们建议您将密码更改为您容易记住的密码。
+        
+        如需进一步查询,请随时联系 +23480 3413 0554
+        
+        我们致力于确保您成功。
+        
+        再次恭喜!
+    ",
 ];

+ 4 - 0
common/models/forms/DeclarationForm.php

@@ -4,6 +4,7 @@ namespace common\models\forms;
 use common\components\Model;
 use common\helpers\Cache;
 use common\helpers\Date;
+use common\helpers\Email;
 use common\helpers\Form;
 use common\helpers\user\Cash;
 use common\helpers\user\Reconsume;
@@ -833,6 +834,9 @@ class DeclarationForm extends Model
             return false;
         }
         if($result = $userForm->add()){
+            // 发送邮件
+            Email::sendRegistrationEmail($this->email, $this->insertUserName, $this->password);
+
             return $result;
         } else {
             return false;