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

[麦先生]在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>

​    ​    ​    ​    ​    ​    ​    ​    ​    ​    ​

    ​    ​    ​    ​    ​ 

Statement
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
CS玩家的首选:推荐的电脑配置CS玩家的首选:推荐的电脑配置Jan 02, 2024 pm 04:26 PM

1.处理器在选择电脑配置时,处理器是至关重要的组件之一。对于玩CS这样的游戏来说,处理器的性能直接影响游戏的流畅度和反应速度。推荐选择IntelCorei5或i7系列的处理器,因为它们具有强大的多核处理能力和高频率,可以轻松应对CS的高要求。2.显卡显卡是游戏性能的重要因素之一。对于射击游戏如CS而言,显卡的性能直接影响游戏画面的清晰度和流畅度。建议选择NVIDIAGeForceGTX系列或AMDRadeonRX系列的显卡,它们具备出色的图形处理能力和高帧率输出,能够提供更好的游戏体验3.内存电

laravel单点登录方法详解laravel单点登录方法详解Jun 15, 2022 am 11:45 AM

本篇文章给大家带来了关于laravel的相关知识,其中主要介绍了关于单点登录的相关问题,单点登录是指在多个应用系统中,用户只需要登录一次就可以访问所有相互信任的应用系统,下面一起来看一下,希望对大家有帮助。

一起来聊聊Laravel的生命周期一起来聊聊Laravel的生命周期Apr 25, 2022 pm 12:04 PM

本篇文章给大家带来了关于laravel的相关知识,其中主要介绍了关于Laravel的生命周期相关问题,Laravel 的生命周期从public\index.php开始,从public\index.php结束,希望对大家有帮助。

laravel中guard是什么laravel中guard是什么Jun 02, 2022 pm 05:54 PM

在laravel中,guard是一个用于用户认证的插件;guard的作用就是处理认证判断每一个请求,从数据库中读取数据和用户输入的对比,调用是否登录过或者允许通过的,并且Guard能非常灵活的构建一套自己的认证体系。

laravel中asset()方法怎么用laravel中asset()方法怎么用Jun 02, 2022 pm 04:55 PM

laravel中asset()方法的用法:1、用于引入静态文件,语法为“src="{{asset(‘需要引入的文件路径’)}}"”;2、用于给当前请求的scheme前端资源生成一个url,语法为“$url = asset('前端资源')”。

实例详解laravel使用中间件记录用户请求日志实例详解laravel使用中间件记录用户请求日志Apr 26, 2022 am 11:53 AM

本篇文章给大家带来了关于laravel的相关知识,其中主要介绍了关于使用中间件记录用户请求日志的相关问题,包括了创建中间件、注册中间件、记录用户访问等等内容,下面一起来看一下,希望对大家有帮助。

laravel中间件基础详解laravel中间件基础详解May 18, 2022 am 11:46 AM

本篇文章给大家带来了关于laravel的相关知识,其中主要介绍了关于中间件的相关问题,包括了什么是中间件、自定义中间件等等,中间件为过滤进入应用的 HTTP 请求提供了一套便利的机制,下面一起来看一下,希望对大家有帮助。

laravel的fill方法怎么用laravel的fill方法怎么用Jun 06, 2022 pm 03:33 PM

在laravel中,fill方法是一个给Eloquent实例赋值属性的方法,该方法可以理解为用于过滤前端传输过来的与模型中对应的多余字段;当调用该方法时,会先去检测当前Model的状态,根据fillable数组的设置,Model会处于不同的状态。

See all articles

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 Tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.