Laravel框架实现的使用smtp发送邮件功能示例
2019/6/30 16:13:44
本文主要是介绍Laravel框架实现的使用smtp发送邮件功能示例,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
本文实例讲述了Laravel框架实现的使用smtp发送邮件功能。分享给大家供大家参考,具体如下:
1、.env文件中配置
MAIL_DRIVER=smtp
MAIL_HOST=smtp.邮箱后缀
MAIL_PORT=邮件服务器发送端口
MAIL_USERNAME=发送方邮件地址
MAIL_PASSWORD=发送方邮箱生成的第三方登陆码
MAIL_FROM_ADDRESS=发送邮箱地址
MAIL_FROM_NAME=发送方名称
2、config目录下mail.php文件配置
可以不配置,因为会被.env文件覆盖掉。(只有在.env中没有的时候才会去该文件中取值)
3、app/console/commonds/sendMail.php
namespace App\Console\Commands; use Illuminate\Console\Command; use Illuminate\Support\Facades\Mail; class SendMailCommand extends Command { /** * The name and signature of the console command. * * @var string */ protected $signature = 'demo:SendMail'; /** * The console command description. * * @var string */ protected $description = '测试脚本SendMail'; /** * constructor */ public function __construct() { parent::__construct(); } /** * Execute the console command. * * @return mixed */ public function handle() { $content = '这是一封的测试邮件.'; $toMail = '目标邮箱'; Mail::raw($content, function ($message) use ($toMail) { $message->subject('[ 测试 ] 测试邮件SendMail - ' .date('Y-m-d H:i:s')); $message->to($toMail); }); } }
4、测试
cmd切换到项目根目录下,执行
php artisan demo:SendMail
更多关于Laravel相关内容感兴趣的读者可查看本站专题:《Laravel框架入门与进阶教程》、《php优秀开发框架总结》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》
希望本文所述对大家基于Laravel框架的PHP程序设计有所帮助。
这篇关于Laravel框架实现的使用smtp发送邮件功能示例的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-09-13手动在github上下载的mfpt包,怎么放到thinkphp5.0框架并正常使用-icode9专业技术文章分享
- 2024-09-05python的<class 'bytearray'>相当于php的哪个数据类型-icode9专业技术文章分享
- 2024-09-05php 导出银行卡号避免科学技术法的方法-icode9专业技术文章分享
- 2024-08-30什么样的php代码质量差被称为垃圾代码-icode9专业技术文章分享
- 2024-08-30用 PHP 调用拼多多的接口以获取订单状态消息的步骤方法和代码示例-icode9专业技术文章分享
- 2024-08-27phpunit单元测试框架的入门和使用方法介绍-icode9专业技术文章分享
- 2024-08-24PHP 中date("w") 周一是多少-icode9专业技术文章分享
- 2024-08-14thinkphp8.0获取域名或主机名方法-icode9专业技术文章分享
- 2024-08-14nginx添加只允许网站根目录index.php可以执行,其他php都不能执行示例代码-icode9专业技术文章分享
- 2024-08-10nginx 如何配置可以访问某个php文件-icode9专业技术文章分享