WasenderApi - Low Cost WhatsApp API for Developers How to Send Laravel Password Reset Links via WhatsApp API (Step-by-Step Guide) - WasenderApi - Low Cost WhatsApp API for Developers
Back to all posts

How to Send Laravel Password Reset Links via WhatsApp API (Step-by-Step Guide)

WasenderAPI
5/1/2025
How to Send Laravel Password Reset Links via WhatsApp API (Step-by-Step Guide)

Password Reset via WhatsApp in Laravel Using WaSenderAPI

Want to improve your Laravel application's user experience and deliverability during password resets? Learn how to implement password reset via WhatsApp using WaSenderAPI, an affordable and reliable WhatsApp messaging platform.

Why Reset Passwords via WhatsApp in Laravel?

Email-based resets are becoming outdated — users often miss the email, it lands in spam, or takes too long to deliver. With WhatsApp password reset integration, you can provide real-time delivery, greater visibility, and a better mobile experience.

WaSenderAPI offers a simple, secure, and developer-friendly API to send WhatsApp messages programmatically, making it perfect for Laravel projects.

What You’ll Learn

  • How to set up WaSenderAPI in Laravel
  • How to send secure password reset links via WhatsApp
  • How to customize notifications and handle failures
  • Best practices for phone validation and token protection

Step 1: Prerequisites

Before starting, make sure you have:

  • Laravel 8 or newer installed
  • A WaSenderAPI account with an active device and API key
  • Composer and GuzzleHTTP installed (composer require guzzlehttp/guzzle)
  • Your users table includes a phone_number column in international format

Step 2: Add the API Key to .env

WASENDER_API_KEY=your-wasender-api-key
        

This allows us to securely access the API from Laravel without hardcoding credentials.

Step 3: Create the WhatsApp Notification Class

php artisan make:notification WhatsAppResetPassword
        

Edit the generated file at app/Notifications/WhatsAppResetPassword.php:

use Illuminate\Notifications\Notification;
use GuzzleHttp\Client;

class WhatsAppResetPassword extends Notification
{
    protected $token;

    public function __construct($token)
    {
        $this->token = $token;
    }

    public function via($notifiable)
    {
        return ['whatsapp'];
    }

    public function toWhatsapp($notifiable)
    {
        $link = url('/password/reset', $this->token) . '?email=' . urlencode($notifiable->email);
        $message = "👋 Hello {$notifiable->name},\n\nClick the link below to reset your password:\n$link\n\nThis link will expire in 60 minutes.";

        try {
            $client = new Client();
            $response = $client->post('https://wasenderapi.com/api/send-message', [
                'headers' => [
                    'Authorization' => 'Bearer ' . env('WASENDER_API_KEY'),
                    'Accept' => 'application/json',
                ],
                'json' => [
                    'to' => [$notifiable->phone_number],
                    'text' => $message,
                ]
            ]);
        } catch (\Exception $e) {
            \Log::error('Failed to send WhatsApp reset link: ' . $e->getMessage());
        }
    }
}
        

Step 4: Update User Model to Use the New Notification

In app/Models/User.php, add:

use App\Notifications\WhatsAppResetPassword;

public function sendPasswordResetNotification($token)
{
    $this->notify(new WhatsAppResetPassword($token));
}
        

Step 5: Validate Phone Numbers in International Format

Ensure that your users provide valid international phone numbers, especially if you’re dealing with WhatsApp delivery.

$request->validate([
    'phone_number' => ['required', 'regex:/^\d{10,15}$/'], // Customize as needed
]);
        

Step 6: Test the Flow

Visit the Laravel password reset page (usually /forgot-password) and enter a user’s email. Laravel will trigger the WhatsApp message using your notification logic.

You can also trigger it manually using:

$user = User::where('email', '[email protected]')->first();
$user->sendPasswordResetNotification(Str::random(60));
        

Advanced Customizations

  • Multi-language support: Use Laravel's localization to send messages in different languages.
  • Rate limiting: Use Laravel's throttle middleware or logic to prevent abuse.
  • Fallback to email: Add email as a fallback in case WhatsApp delivery fails.

Security Best Practices

  • Use HTTPS for all reset links
  • Log WhatsApp sending attempts and errors securely
  • Store phone numbers in an encrypted database column if needed
  • Set a short token expiration time (Laravel default is 60 minutes)

Real-World Use Cases

  • SaaS Platforms: Allow password reset via WhatsApp for B2B users on the go
  • E-Commerce: Ensure timely password reset for shoppers who can’t wait for emails
  • Internal Tools: Speed up employee access recovery through WhatsApp

Conclusion

With just a few tweaks, you’ve now implemented a modern, fast, and reliable WhatsApp-based password reset system in Laravel using WaSenderAPI. This solution improves UX and fits both customer-facing apps and internal tools.

Get Started with WaSenderAPI to revolutionize your Laravel workflows.

Frequently Asked Questions

Can I send a verification code instead of a link?

Yes. You can generate a short numeric token, save it in the database, and prompt the user to enter it on a verification page.

How do I know if the WhatsApp message failed?

WaSenderAPI returns a response object. You can log the response status or message and implement retry logic if needed.

Is WaSenderAPI GDPR compliant?

WaSenderAPI stores only essential metadata and does not read message content. Still, you should update your privacy policy accordingly.

Can I combine email and WhatsApp notifications?

Yes. In your via() method, return both ['mail', 'whatsapp'] and customize the notification content for each channel.

Related Posts

Best Waapi Alternative in 2025 – Reliable WhatsApp API WasenderAPI
WhatsApp API Tutorials

Best Waapi Alternative in 2025 – Reliable WhatsApp API WasenderAPI

Looking for a reliable Waapi alternative? WaSenderAPI is the best WhatsApp API in 2025 with 99.9% uptime, unlimited messages, multi-session support & 3-day free trial.

WasenderAPI
7/30/2025
waapi ya no funciona: Descubre la mejor alternativa con WaSenderAPI
WhatsApp for Developers

waapi ya no funciona: Descubre la mejor alternativa con WaSenderAPI

¿waapi.app está caído? Descubre por qué WaSenderAPI es la mejor alternativa no oficial a la API de WhatsApp. Envío ilimitado, integración fácil y sin complicaciones.

WasenderAPI
7/11/2025
A Melhor API de WhatsApp Não Oficial para Desenvolvedores no Brasil – Conheça o WaSenderAPI
WhatsApp for Developers

A Melhor API de WhatsApp Não Oficial para Desenvolvedores no Brasil – Conheça o WaSenderAPI

Procura uma alternativa acessível à API oficial do WhatsApp? Conheça o WaSenderAPI – API poderosa, fácil de integrar e sem limite de mensagens. Ideal para desenvolvedores e empresas no Brasil.

WasenderAPI
7/11/2025