fekharmensour/otp-mailer 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

fekharmensour/otp-mailer

最新稳定版本:v1.0.0

Composer 安装命令:

composer require fekharmensour/otp-mailer

包简介

Standalone OTP mailer package for Laravel (send OTP codes)

README 文档

README

Standalone OTP mailer package for Laravel — send one-time passwords (OTP) to user emails.

Installation

  1. Require the package via Composer:
composer require fekharmensour/otp-mailer
  1. (Optional) If your app does not auto-discover packages, register the service provider and alias in config/app.php:
  • Provider: Fekharmensour\OtpMailer\OtpMailerServiceProvider
  • Alias: OtpMailer => Fekharmensour\OtpMailer\Facades\OtpMailer

Publish configuration

The package ships a config file. Publish it with this command:

php artisan vendor:publish --provider="Fekharmensour\OtpMailer\OtpMailerServiceProvider" --tag=config

This will copy config/otp-mailer.php to your application's config folder. You can also copy config/otp-auth.php from the package if you need the legacy compatibility file.

Environment / SMTP setup

The package sends emails using Laravel's mail system. Add your SMTP credentials to .env. For example (Gmail app password):

MAIL_MAILER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=youremail@gmail.com
MAIL_PASSWORD=your_app_password
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=youremail@gmail.com
MAIL_FROM_NAME="Your App"

Note: For Gmail use an App Password (requires 2FA). Replace your_app_password with that app password.

Usage (simple route)

The package exposes a facade OtpMailer (and backward-compatible OtpAuth). Use generateAndSend(string $email) to create and email a 6-digit OTP, and validate(string $email, string $code) to validate it.

Example route (routes/web.php):

use Fekharmensour\OtpMailer\Facades\OtpMailer;
use Illuminate\Http\Request;

Route::get('/send-otp', function () {
	$email = 'user@example.com';
	$code = OtpMailer::generateAndSend($email);

	return "OTP sent to {$email}"; // do not reveal the code in production
});

Route::post('/verify-otp', function (\\Illuminate\\Http\\Request $request) {
	$email = $request->input('email');
	$code = $request->input('code');

	$valid = OtpMailer::validate($email, $code);

	return response()->json(['valid' => $valid]);
});

Usage (controller)

In a controller you can call the same facade methods:

use Fekharmensour\OtpMailer\Facades\OtpMailer;

public function send(Request $request)
{
	$email = $request->input('email');
	OtpMailer::generateAndSend($email);

	return back()->with('status', 'OTP sent');
}

Configuration

Open config/otp-mailer.php to change TTL, cache prefix, or the Notification class used to send the email. The default notification class is Fekharmensour\\OtpMailer\\Notifications\\OtpNotification.

Troubleshooting

  • Ensure your mail settings in .env are correct and that the app can send mail (try php artisan tinker + \\Mail::raw('test', function($m){$m->to('you@example.com')->subject('test');});).
  • For Gmail use an App Password and enable the correct security settings.

License

MIT

统计信息

  • 总下载量: 2
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-02-05

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固