Table of Contents
[麦先生]在Laravel框架里实现邮箱验证---发送邮件,laravel---
Home php教程 php手册 [麦先生]在Laravel框架里实现邮箱验证---发送邮件,laravel---

[麦先生]在Laravel框架里实现邮箱验证---发送邮件,laravel---

Jun 13, 2016 am 08:39 AM
laravel send exist accomplish frame mail Mail verify

[麦先生]在Laravel框架里实现邮箱验证---发送邮件,laravel---

      在经过一段时间的使用后,发现在项目中很多地方需要用到用户验证,以短信验证和邮箱验证为主流趋势,小麦总结了如果在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 消息生成器实例中可以使用的方法清单:

<code class=" language-php"><span class="token variable">$message<span class="token operator">-<span class="token operator">><span class="token function">from<span class="token punctuation">(<span class="token variable">$address<span class="token punctuation">, <span class="token variable">$name <span class="token operator">= <span class="token keyword">null<span class="token punctuation">)<span class="token punctuation">;
<span class="token variable">$message<span class="token operator">-<span class="token operator">><span class="token function">sender<span class="token punctuation">(<span class="token variable">$address<span class="token punctuation">, <span class="token variable">$name <span class="token operator">= <span class="token keyword">null<span class="token punctuation">)<span class="token punctuation">;
<span class="token variable">$message<span class="token operator">-<span class="token operator">><span class="token function">to<span class="token punctuation">(<span class="token variable">$address<span class="token punctuation">, <span class="token variable">$name <span class="token operator">= <span class="token keyword">null<span class="token punctuation">)<span class="token punctuation">;
<span class="token variable">$message<span class="token operator">-<span class="token operator">><span class="token function">cc<span class="token punctuation">(<span class="token variable">$address<span class="token punctuation">, <span class="token variable">$name <span class="token operator">= <span class="token keyword">null<span class="token punctuation">)<span class="token punctuation">;
<span class="token variable">$message<span class="token operator">-<span class="token operator">><span class="token function">bcc<span class="token punctuation">(<span class="token variable">$address<span class="token punctuation">, <span class="token variable">$name <span class="token operator">= <span class="token keyword">null<span class="token punctuation">)<span class="token punctuation">;
<span class="token variable">$message<span class="token operator">-<span class="token operator">><span class="token function">replyTo<span class="token punctuation">(<span class="token variable">$address<span class="token punctuation">, <span class="token variable">$name <span class="token operator">= <span class="token keyword">null<span class="token punctuation">)<span class="token punctuation">;
<span class="token variable">$message<span class="token operator">-<span class="token operator">><span class="token function">subject<span class="token punctuation">(<span class="token variable">$subject<span class="token punctuation">)<span class="token punctuation">;
<span class="token variable">$message<span class="token operator">-<span class="token operator">><span class="token function">priority<span class="token punctuation">(<span class="token variable">$level<span class="token punctuation">)<span class="token punctuation">;
<span class="token variable">$message<span class="token operator">-<span class="token operator">><span class="token function">attach<span class="token punctuation">(<span class="token variable">$pathToFile<span class="token punctuation">, <span class="token keyword">array <span class="token variable">$options <span class="token operator">= <span class="token punctuation">[<span class="token punctuation">]<span class="token punctuation">)<span class="token punctuation">;
<span class="token comment">
// 以原始 $data 字符串附加一个文件...
<span class="token variable">$message<span class="token operator">-<span class="token operator">><span class="token function">attachData<span class="token punctuation">(<span class="token variable">$data<span class="token punctuation">, <span class="token variable">$name<span class="token punctuation">, <span class="token keyword">array <span class="token variable">$options <span class="token operator">= <span class="token punctuation">[<span class="token punctuation">]<span class="token punctuation">)<span class="token punctuation">;
<span class="token comment">
// 获取底层的 SwiftMailer 消息实例...
<span class="token variable">$message<span class="token operator">-<span class="token operator">><span class="token function">getSwiftMessage<span class="token punctuation">(<span class="token punctuation">)<span class="token punctuation">;</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></code>
Copy after login

​    ​    ​    ​    ​    ​    ​    ​    ​    ​    ​

    ​    ​    ​    ​    ​ 

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Sesame Open Door Exchange Web Page Login Latest version gateio official website entrance Sesame Open Door Exchange Web Page Login Latest version gateio official website entrance Mar 04, 2025 pm 11:48 PM

A detailed introduction to the login operation of the Sesame Open Exchange web version, including login steps and password recovery process. It also provides solutions to common problems such as login failure, unable to open the page, and unable to receive verification codes to help you log in to the platform smoothly.

okx Ouyi official website registration portal 2025 okx Ouyi official website registration portal 2025 Mar 04, 2025 pm 11:45 PM

OKX Ouyi is a leading cryptocurrency trading platform. This article will provide detailed steps to guide you on how to register an OKX Ouyi official website account. You will learn how to access the official website, choose the registration method, fill in the necessary information, and complete the registration process. The article also contains information about precautions, such as the importance of using real personal information and setting a strong password.

gate.io registration tutorial gate.io registration tutorial Mar 31, 2025 pm 11:09 PM

This article provides a detailed Gate.io registration tutorial, covering every step from accessing the official website to completing registration, including filling in registration information, verifying, reading user agreements, etc. The article also emphasizes security measures after successful registration, such as setting up secondary verification and completing real-name authentication, and gives tips from beginners to help users safely start their digital asset trading journey.

How to register and download the latest app on Bitget official website How to register and download the latest app on Bitget official website Mar 05, 2025 am 07:54 AM

This guide provides detailed download and installation steps for the official Bitget Exchange app, suitable for Android and iOS systems. The guide integrates information from multiple authoritative sources, including the official website, the App Store, and Google Play, and emphasizes considerations during download and account management. Users can download the app from official channels, including app store, official website APK download and official website jump, and complete registration, identity verification and security settings. In addition, the guide covers frequently asked questions and considerations, such as

How to implement the custom table function of clicking to add data in dcat admin? How to implement the custom table function of clicking to add data in dcat admin? Apr 01, 2025 am 07:09 AM

How to implement the table function of custom click to add data in dcatadmin (laravel-admin) When using dcat...

The latest registration portal for Ouyi official website The latest registration portal for Ouyi official website Mar 21, 2025 pm 05:54 PM

As the world's leading digital asset trading platform, Ouyi OKX attracts many investors with its rich trading products, strong security guarantees and convenient user experience. However, the risks of network security are becoming increasingly severe, and how to safely register the official Ouyi OKX account is crucial. This article will provide the latest registration portal for Ouyi OKX official website, and explain in detail the steps and precautions for safe registration, including how to identify the official website, set a strong password, enable two-factor verification, etc., to help you start your digital asset investment journey safely and conveniently. Please note that there are risks in digital asset investment, please make cautious decisions.

binance download APP binance Binance platform download free APP binance download APP binance Binance platform download free APP Mar 18, 2025 pm 01:54 PM

This article introduces in detail two methods for downloading Binance APP on Apple iOS system and Android system mobile phones. For iOS systems, since the App Store in China cannot be downloaded directly, users need to use the Apple ID in the outer zone, and they can choose to borrow or register the Apple ID in the outer zone to download it. Android users can directly search and install it in the app store, or visit Binance's official website to scan the QR code to download the installation package. It should be noted that when downloading applications from unofficial channels, you may need to enable the application installation permissions of unknown sources on your phone. No matter which system you are, you can use the Binance APP after downloading.

How to buy Bitcoin on Alipay? Alipay Buy BTC Complete Tutorial How to buy Bitcoin on Alipay? Alipay Buy BTC Complete Tutorial Mar 05, 2025 pm 06:03 PM

Alipay and Bitcoin Transactions: A safe and convenient purchasing guide Alipay is a widely used payment tool in China. Although it does not support direct purchase of cryptocurrencies such as Bitcoin, you can complete transactions indirectly through some channels. This article will guide you on how to use Alipay to purchase Bitcoin safely and conveniently, and explain the risks that need to be paid attention to. The most common way to purchase Bitcoin indirectly through cryptocurrency exchanges is to trade through cryptocurrency exchanges that support Alipay. This method usually requires you to buy USDT (stablecoin) first and then exchange USDT for Bitcoin. The following is an example of Ouyi OKX Exchange, explain the operation steps in detail: Register Ouyi OKX account: Visit Ouyi OKX official website (click to register), register an account using email address, and complete

See all articles