当前位置:网站首页>Laravel 使用QQ邮箱发送邮件
Laravel 使用QQ邮箱发送邮件
2022-08-07 18:55:00 【历史老师-】
一、配置 QQ 邮箱
具体步骤:设置 > 账户 > POP3/IMAP/SMTP/Exchange/CardDAV/CalDAV 服务
1.打开邮箱,点击设置

2.开启发送邮件服务

3.得到秘钥
二、配置 Laravel .env 文件
// .env
MAIL_DRIVER=smtp
MAIL_HOST=smtp.qq.com // 邮箱服务器
MAIL_PORT=465 // 端口
[email protected] // 邮件发送者名称(自己)
MAIL_PASSWORD=**************** // 邮件秘钥(开通服务后的秘钥)
MAIL_ENCRYPTION=ssl // 加密传输
[email protected] // 邮件发送者地址(自己)这个必须与MAIL)USERNAME一致
MAIL_FROM_NAME=xxx // 发送者名称,可自定义三、定义路由与创建控制器
// 步骤一:创建控制器
// app/Http/Controllers/Home/UserController.php
php artisan make:controller Home/UserController
// 步骤二:定义路由
// app/routes/web.php
// 发送普通文本信息
Route::get('send' , 'Home\[email protected]');
Route::get('sendbeauty' , 'Home\[email protected]');四、发送邮件
// app/Http/Controllers/UserController.php
<?php
namespace App\Http\Controllers\Home;
use App\Http\Controllers\Controller;
use Illuminate\Mail\Message;
class UserController extends Controller
{
// 发送普通文本信息
public function index()
{
\Mail::raw('自如初-测试邮件发送' , function(Message $message){
// 邮件接收者
$message->to('****@qq.com');
// 邮件主题
$message->subject('hello world');
});
}
// 发送富文本邮件
public function beauty()
{
/**
* send(参数1,参数2)
*
* 参数1:视图
* 参数2:要传递给视图的数据信息
*/
\Mail::send('mail.beauty',['msg'=>'自如初个人博客,一个记录生活与学习的博客'],function(Message $message){
// 发给谁
$message->to('****@qq.com');
// 发送的主题
$message->subject('hello world');
});
}
/*发送富文本模板
Mail::send('视图',compact('user'),function ($message) use ($user){
$to = 收件人;
$message->to($to)->subject('发送主题');
*/
});
}五、静态页面
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>富文本邮件</title>
<style>
div {
font-size: 18px;
font-weight: bold;
color:green;
}
</style>
</head>
<body>
<h1>{
{ $msg }}</h1>
{
{-- 图片标签 --}}
<div>
自如初个人博客
</div>
</body>
</html>
边栏推荐
- 离线地图下载和发布
- 合规运营必备资质——ICP申请指南
- Scala entry to proficient (Shang Silicon Valley study notes)
- vulnhub靶机22 02-Breakout.zip
- Intel Locked Atomic Operations
- 卡尔曼滤波
- 【Leetcode-链表强训】
- Free translation software - batch automatic one-click translation
- 第61章 Jquery JSON Table EntityFrameworkCore自动生成数据库
- Introduction to functions - understanding of the container_of macro
猜你喜欢
随机推荐
vim you can also write text blocks
Which translation software is more accurate
【Token】JWT uses Token to log in
基于 nacos/灰度发布 实现减少本地启动微服务数量的实践
【ROS2原理7】中间件和接口(interface)
图像坐标转像素坐标得到偏差
[2022 杭电多校5] Count Set (生成函数 分治NTT)
XSS 攻击是什么?
字符串去掉()以及()中的文字
Three ways to splicing int type variables and String type variables in dart
陆金所管理层动荡:冀光恒卸任董事长职务 CFO郑锡贵也退休
2022-8-7
Graduation Summary
[RoarCTF 2019]Easy Calc
"Principles of Programming" Reading Notes (1): Prerequisites and Guidelines for Programming
每天20分钟之hystrix
C# calls bartender for dynamic printing and complete tutorial of batch printing
[GStreamer] undefined symbol: gst_push_src_get_type
翻译软件哪个准确度高
学内核之五:问题二,原子操作与锁









