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消息生成器实例中可以使用的方法清单:

$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();

​​​​​​​​​

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

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)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function