Laravel框架实现的使用smtp发送邮件功能示例
2019-05-29 15:18
971 查看
本文实例讲述了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框架实现的使用smtp发送邮件功能示例
- thinkphp框架使用PHPMailer实现发送邮件的功能,以及各种问题解析
- 在 Laravel 5.1 中使用SMTP驱动实现邮件发送(含附件和图片)详细教程
- Laravel5.0+框架邮件发送功能实现方法图文与实例详解
- Laravel框架实现SMTP发送邮件
- Laravel框架中使用邮件发送功能
- PHP_thinkphp框架使用PHPMailer实现发送邮件的功能,以及各种问题解析
- 在asp.NET 中使用SMTP发送邮件的实现代码
- 使用Nvelocity实现发送邮件功能(ASP.NET MVC2环境下)
- Laravel框架实现的批量删除功能示例
- 如何在 Laravel 中使用 SMTP 发送邮件(适用于 163、QQ、Gmail 等)
- 使用JavaMail实现发送邮件功能
- 在asp.NET 中使用SMTP发送邮件的实现代码
- 使用UTL_SMTP包实现存储过程邮件发送
- [麦先生]在Laravel框架里实现邮箱验证---发送邮件
- 使用libcurl库实现SMTP发送邮件
- 使用Pear和php socket来实现通过smtp验证发送邮件
- Python发送邮件功能示例【使用QQ邮箱】
- tp5(thinkPHP5框架)使用DB实现批量删除功能示例
- 使用MailMessage和SmtpClient类实现asp.net的邮件发送(有详细注释并已测试通过)