Browse Source

测试邮件发送

zhangdehua 9 tháng trước cách đây
mục cha
commit
b7cdc351ae
2 tập tin đã thay đổi với 47 bổ sung8 xóa
  1. 30 1
      app/index/controller/Captcha.php
  2. 17 7
      app/index/service/passport/MailCaptcha.php

+ 30 - 1
app/index/controller/Captcha.php

@@ -106,4 +106,33 @@ class Captcha extends Controller
         }
         return $this->renderError('not match');
     }
-}
+
+    /**
+     * 发送邮箱验证码
+     * @return Json
+     * @throws BaseException
+     */
+    public function sendEmailCaptchaSm(): Json
+    {
+        $data = $this->postForm();
+        $email = $data['mobile'] ?? '';
+        if (empty($email) || !is_email($email)) {
+            return $this->renderError('Invalid email address.');
+        }
+
+        $smtp = new MailCaptchaService();
+        $flag = $smtp->sendCaptcha($email);
+        if ($flag) {
+            return $this->renderSuccess('Sent Successful!Please check your new mails.');
+        }
+        log_record($smtp->getError(), 'error');
+        return $this->renderError('Failed to send code. Please try again later');
+
+
+//        $MailCaptchaService = new MailCaptchaService;
+//        if ($MailCaptchaService->handle($this->postForm())) {
+//            return $this->renderSuccess('Sent Successful!Please check your new mails.');
+//        }
+//        return $this->renderError($MailCaptchaService->getError() ?: 'Failed to send code. Please try again later');
+    }
+}

+ 17 - 7
app/index/service/passport/MailCaptcha.php

@@ -76,7 +76,7 @@ class MailCaptcha extends BaseService
         //dd(config('smtp'));
         try {
             //Server settings
-            $mail->SMTPDebug = SMTP::DEBUG_OFF;//DEBUG_OFF,DEBUG_SERVER           //Enable verbose debug output
+            $mail->SMTPDebug = SMTP::DEBUG_SERVER;//DEBUG_OFF,DEBUG_SERVER           //Enable verbose debug output
             $mail->SMTPOptions = array(
                 'ssl' => array(
                     'verify_peer' => false,
@@ -84,16 +84,26 @@ class MailCaptcha extends BaseService
                     'allow_self_signed' => true
                 )
             );
-            $mail->isSMTP();                                            //Send using SMTP
+/*            $mail->isSMTP();                                            //Send using SMTP
             $mail->Host = config('smtp.host');                     //Set the SMTP server to send through
             $mail->SMTPAuth = true;                                   //Enable SMTP authentication
             $mail->Username = config('smtp.username');                   //SMTP username
             $mail->Password = config('smtp.password');                               //SMTP password
             $mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;            //Enable implicit TLS encryption
-            $mail->Port = config('smtp.port');                                    //TCP port to connect to; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS`
+            $mail->Port = config('smtp.port');  */                                  //TCP port to connect to; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS`
 
             //Recipients
-            $mail->setFrom(config('smtp.from_address'), config('smtp.from_name'));
+            //$mail->setFrom(config('smtp.from_address'), config('smtp.from_name'));
+
+            $mail->isSMTP();                                            //Send using SMTP
+            $mail->Host = 'tls://smtp.office365.com';//config('smtp.host');                     //Set the SMTP server to send through
+            $mail->SMTPAuth = true;                                   //Enable SMTP authentication
+            $mail->Username = 'register@freeshippingvapes.com';//config('smtp.username');                   //SMTP username
+            $mail->Password = 'Iloveyou1@#';//config('smtp.password');                               //SMTP password
+            $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;            //Enable implicit TLS encryption
+            $mail->Port = 587;//;config('smtp.port');
+            $mail->setFrom('register@freeshippingvapes.com', 'Free Shipping Vps');
+
             $mail->addAddress($email, 'FSV');     //Add a recipient
             //$mail->addAddress('ellen@example.com');               //Name is optional
             //$mail->addReplyTo('info@example.com', 'Information');
@@ -108,7 +118,7 @@ class MailCaptcha extends BaseService
             //$mail->isHTML(true);                                  //Set email format to HTML
             $mail->Subject = 'Password';
             $mail->Body = 'Your code is ' . $smsCaptcha . '.Please use it in 15 minutes';
-            $mail->AltBody = 'This is the Your Code for Free Shipping Vapes';
+            $mail->AltBody = 'This is the Your Code for FreeShippingV';
 
             $mail->send();
             //echo 'Message has been sent';
@@ -150,7 +160,7 @@ class MailCaptcha extends BaseService
             $mail->SMTPAuth = true;                                   //Enable SMTP authentication
             $mail->Username = config('smtp.username');                   //SMTP username
             $mail->Password = config('smtp.password');
-            $mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;            //Enable implicit TLS encryption
+            $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;            //Enable implicit TLS encryption
             $mail->Port = config('smtp.port');                                    //TCP port to connect to; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS`
 
             //Recipients
@@ -232,4 +242,4 @@ class MailCaptcha extends BaseService
         }
         return true;
     }
-}
+}