
-
免费
-
免费
-
免费
-
免费
-
免费
-
免费
-
免费
-
免费
-
免费
-
免费
-
免费
-
免费
-
免费
-
免费
-
免费
-
免费
-
免费
播放列表
0 人点赞
课程内容
邮件发送
Laravel 基于 SwiftMailer 库提供了一套干净、清爽的邮件 API。Laravel 为 SMTP、Mailgun、Postmark、Amazon SES,以及 sendmail 提供了驱动,从而允许你快速通过本地或云服务发送邮件。
安装包
composer require guzzlehttp/guzzle
驱动
虽然提供了很低启动,但是很多用不到,所以我这里还是直接用默认 smtp
启动,大家可以在腾讯里面申请,也可以在其他邮箱里面申请即可,如果是企业邮箱,就可以直接开通,个人的话,可能会有一些限制
发送邮箱要求
- 必须有邮箱地址,也就是必须配置
from.address
- 必须有邮箱地址名字,也就是必须配置
from.name
- 发送邮箱地址必须和
from.address
相同
创建一个邮箱处理类
php artisan make:mail RegistMail
配置发件人 ,2种形式,一种直接写方法,一种直接在
build
里面调用这些方法
app/Mail/RegistMail.php
文件
<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;//队列包含了
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;//序列化模型
class RegistMail extends Mailable
{
use Queueable, SerializesModels;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->view('view.name');
}
}
第一种配置方法
from,来自
subject, 标题
view, 视图
attach 附件
<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
class RegistMail extends Mailable
{
use Queueable, SerializesModels;
//这里定义邮箱的发送源
public $from = [
[
'address' => 'email@kong-qi.com',
'name' => '测试邮箱'
]
];
public $config;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct($data)
{
//
$this->config = $data;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->view('mail');
}
}
增加文件头
public $subject='注册邮箱通知';
第二种方法
<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
class RegistMail extends Mailable
{
use Queueable, SerializesModels;
public $config;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct($data)
{
//
$this->config = $data;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->view('mail')->subject('内部注册通知')->from(
[
'address' => 'email@kong-qi.com',
'name' => '测试邮箱'
]
);
}
}
调用发送邮件
to 就是接受的邮箱地址
Mail::to('531833998@qq.com')->send(new RegistMail($mail_data));
new RegistMail($mail_data) 注入的内容,可以是类,也可以是数组
$mail_data=[
'name'=>'空气',
'content'=>'我是测试数据的内容'
];
Mail::to('531833998@qq.com')->send(new RegistMail($mail_data));
<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
class RegistMail extends Mailable
{
use Queueable, SerializesModels;
public $config;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct($data)
{
//
$this->config=$data;//这个config属性会自动共享给视图文件,这里是config,那么必须是public 属性才可以,然后视图文件直接就$config['name']
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->view('mail');
}
}
视图文件
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>我是测试邮箱</title>
</head>
<body>
<h3>我是测试邮箱:{{ $config['name'] }}</h3>
<p>{{ $config['content'] }}</p>
</body>
</html>
队列使用
Mail::to('531833998@qq.com')->queue(new RegistMail($mail_data));
开启了redis
php artisan queue:work
后台运行
php artisan queue:work&
课件
评论区 (0)
最新视频教程
-
-
黑白课堂
- Laravel6 全套入门实战
- 4642 2
-
-
-
黑白课堂
- Laravel6 全套入门实战
- 4557 5
-
-
-
黑白课堂
- Laravel6 全套入门实战
- 4443 0
-
-
-
黑白课堂
- Laravel6 全套入门实战
- 4065 0
-
-
-
黑白课堂
- Laravel6 全套入门实战
- 4063 0
-
最新视频课程
-
Laravel 消息通知使用
黑白课堂
284614 03年前
-
ace.js 打造一款属于你的 Web 编辑器,入门文档。
黑白课堂
15257 04年前
-
Laravel 实现 RBAC 权限管理功能 Permission 包操作
黑白课堂
14111 04年前
-
微信小程序等比例图片压缩上传,100%可用,非官方压缩方法
黑白课堂
12162 14年前
-
宝塔面板强制绑定账号修改为不强制绑定方案
黑白课堂
11348 02年前
-
wap2App 入门讲解,100%速成,全面为你讲解。
黑白课堂
9187 04年前
-
Laravel 设置请求头 header 参数
黑白课堂
8314 03年前
-
Laravel 的 PhpSpreadsheet 包入门
黑白课堂
8309 04年前
-
Laravel 表格操作 Maatwebsite/Laravel-Excel 3.1 最新版本的操作指南
黑白课堂
8286 04年前
-
Linux 下如何监听我们的脚本是否掉线了
黑白课堂
7550 02年前
-
KongQi Laravel Admin2.0 文档安装
黑白课堂
3905 23年前
-
KongQi Laravel admin2.0 layui admin 版本序言
黑白课堂
3330 03年前
-
易语言入门拖入文件导入到超级列表框表格内
哪吒
8373 13年前
-
易语言入门易语言定时任务模块
哪吒
6464 03年前
-
postman 使用手册cookie 使用
哪吒
4970 03年前
-
谷歌浏览器插件教程proxy 代理
哪吒
4506 01年前
-
易语言入门判断文件夹是否存在的方法
哪吒
4216 02年前
-
易语言入门TAB 标签页制作
哪吒
4192 03年前
-
Visual Studio Code 入门和使用教程插件安装使用
哪吒
4122 13年前
-
Visual Studio Code 入门和使用教程安装下载
哪吒
4092 03年前
