max 10 месяцев назад
Родитель
Сommit
9565548d1b

+ 15 - 1
common/config/main.php

@@ -58,7 +58,21 @@ 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',
+
+//                'host' => 'smtp.163.com',
+//                'port' => 465,
+//                'username' => '18511880790@163.com',
+//                'password' => 'YOUSSWQHISDSWPVB',
+//                'encryption' => 'SSL',
+            ],
         ],
         'swooleAsyncTimer' => [
             'class' => 'common\components\SwooleAsyncTimer',

+ 29 - 0
common/helpers/Email.php

@@ -0,0 +1,29 @@
+<?php
+
+namespace common\helpers;
+
+use Yii;
+
+class Email
+{
+    /**
+     * @param string $email
+     * @param string $userName
+     * @param string $password
+     */
+    public static function sendRegistrationEmail(string $email, string $userName, string $password)
+    {
+        $subject = 'Elken Welcome You.';
+        $str = "<p>恭喜!  恭喜您成功注册到Elken Global系统和家庭。  我们致力于打造你来打造他人  使用下面提供的链接登录您的后台办公室  <a href='https://ngds.elken.com/#/login'>Member Management System</a>   用户名=".$userName." 密码=".$password."  我们建议您将密码更改为您容易记住的密码。  如需进一步查询,请随时联系+23480 3413 0554  我们致力于确保您成功。  再次恭喜!</p>";
+        $message = \Yii::t('app', $str);
+
+        $mailer = Yii::$app->mailer;
+        $mailer->useFileTransport = false;
+        $mailer->compose()
+            ->setFrom('eshop-noreply@elken.com')
+            ->setTo($email)
+            ->setSubject($subject)
+            ->setHtmlBody($message)
+            ->send();
+    }
+}

+ 3 - 0
frontendApi/modules/v1/controllers/UserController.php

@@ -10,6 +10,7 @@ namespace frontendApi\modules\v1\controllers;
 
 use common\helpers\bonus\CalcCache;
 use common\helpers\Cache;
+use common\helpers\Email;
 use common\helpers\Form;
 use common\helpers\LoggerTool;
 use common\helpers\Tool;
@@ -625,6 +626,8 @@ SQL;
 
             $allData['data'][] = $post;
             if ($formModel->load($allData, '') && $result = $formModel->add()) {
+                //发送邮件
+                Email::sendRegistrationEmail($post['email'], $post['userName'], $post['password']);
                 return static::notice($result);//报单成功
             } else {
                 return static::notice(Form::formatErrorsForApi($formModel->getErrors()),400);