[麥先生]在Laravel架構裡實現郵箱驗證-發送郵件

來源:互聯網
上載者:User
      在經過一段時間的使用後,發現在項目中很多地方需要用到使用者驗證,以簡訊驗證和郵箱驗證為主流趨勢,小麥總結了如果在Laravel架構中實現發送郵件功能,以後會陸續更上如何?簡訊驗證.....  

      

      

在.env檔案下

1.配置Laravel檔案

MAIL_DRIVER=smtp //建議使用smtp方式

MAIL_HOST=smtp.163.com //建議使用163郵箱 QQ郵箱會有報錯

MAIL_PORT=25 //smtp 預設為25

MAIL_USERNAME=null //自己的163帳號

MAIL_PASSWORD=null //用戶端密碼

MAIL_ENCRYPTION=null

.

2.修改config/email.php檔案中的

'from' => ['address' => null, 'name' => null], //手冊上未提示,但實際應用中 如果為addredd=>null則報錯,需要天寫自己的163地址

3. 註冊163的郵箱並進行郵箱帳號設定 POP3/SMTP/IMAP都要開啟 並開啟授權碼並進行手機驗證

4.參照Laravel手冊裡的郵件發送

必須注意的是 在控制器引用郵件發送時 必須首先引用use Mail

發送郵件測試

在路由裡設定

      

在控制器中寫入方法

                

其中

1:Mail::raw 是發送原生資料,其他的內容發送方式在手冊裡都有提供;

2.$message->subjuet('');是檔案的標題

3.$message->to();發送給誰

這是一份在 $message 訊息產生器執行個體中可以使用的方法清單:

$message->from($address, $name = null);$message->sender($address, $name = null);$message->to($address, $name = null);$message->cc($address, $name = null);$message->bcc($address, $name = null);$message->replyTo($address, $name = null);$message->subject($subject);$message->priority($level);$message->attach($pathToFile, array $options = []);// 以原始 $data 字串附加一個檔案...$message->attachData($data, $name, array $options = []);// 擷取底層的 SwiftMailer 訊息執行個體...$message->getSwiftMessage();

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.