Platform
Docs
Solutions
ContactLog In

Get started sending notifications with Courier in minutes, not days!

We have SDKs in Ruby, Go, Python, Javascript, Node.js, and React.

Sign up

Header image for the Sending Password Reset Notifications with Laravel tutorial
TUTORIAL

Sending Password Reset Notifications from Your Laravel PHP Framework

Sarah Barber

June 06, 2023

Resetting passwords is a critical way to make your app accessible to users, but setting up email notifications for password resets from scratch can be tedious and error-prone. While Laravel does support password reset email templates, Laravel emails can be unreliable and prone to being caught in spam filters, and the default email templates are not particularly customizable. It might also be desirable to set up a backup channel like SMS or a backup email provider in case the primary fails.

That’s where Courier comes in. Courier offers complete notification infrastructure with an API that simplifies some of the most complex notification logic, allowing you to notify customers across multiple channels (including email, SMS, push, chat apps, and more). You can also use Courier's no-code web tools to design templates and communication sequences, and make use of its analytics dashboard to monitor delivery and engagement metrics.

By using Courier to send Laravel notifications, you can send multi-channel alerts via email, SMS, push, and other channels based on your users’ preferences or actions, with the results all being reported back to one centralized analytics and logging console.

In this tutorial, we'll show you how to implement PHP Laravel password reset notifications the right way, using the Courier PHP SDK. The examples in this tutorial will use Gmail to send mail, but Courier supports a number of other email service providers as well.

Step 1: Prepare your Laravel code environment

  • Ensure you have the latest versions of PHP, Composer, and Laravel installed.
  • The Courier SDK uses HTTPlug to send requests, which defaults to using the Guzzle HTTP client. Make sure that this is included as a dependency in your Laravel project by running:

  • Add the Courier PHP SDK package to your Laravel project using Composer:

Step 2: Configure your email service provider in Courier

If you don’t have a Courier account, create one now.

Before you can send emails using Courier, you must configure an email service provider. In the Courier app, navigate to Channels and select your email service provider from the Provider Catalog. For this tutorial, we will be using Gmail.

sending-password-reset-notifications-with-laravel-11

Next, select Sign in with Google and give Courier access to your Google account. Now you have configured Gmail as an email provider.

Note that Courier does offer channel failover (eg. to SMS) or provider failover in the event that the primary email provider (in this case, Gmail) fails.

Step 3: Design your password reset notification template in Courier

Navigate to Designer in Courier, and click the Create Template button to create a new template, and name it Reset password. If you check the box Use AI to generate notification content, an email template will be generated for you, based on your notification name. Click Create Template again.

sending-password-reset-notifications-create-notification-template

You will now be prompted to select the notification channels you want to be able to send your notifications to. Select Email as your notification channel, and add Gmail as its provider in the drop-down box (which will be available to you if you configured this in step 2). Then, click on your new email channel on the left of your screen to start adding content to your notification template.

sending-password-reset-notifications-laravel-add-email-channel

Use Courier’s template editor to write the content for your password reset notification. Courier allows variables in its email templates, which you can add using curly braces. Courier will highlight these variables in green for easy visibility.

sending-password-reset-notifications-with-laravel-12

Changing the branding of your email notification template

Click on the three dots icon on your notification template to edit your brand. You can add a brand logo, change your brand color scheme, and add headers, footers, and links to your company social network profiles.

sending-password-reset-notifications-laravel-brands

Changing your branding will result in the branding being changed on your password reset email when it is sent:

sending-password-reset-notifications-with-laravel-10

Finalizing your notification template

sending-password-reset-notifications-with-laravel-8

Now click Publish Changes to publish the new notification, and then click the settings button for your notification template, which is near the top left corner of the window.

In the settings, you will see a Notification ID, which is the ID of this template. You will use this later, to refer to this notification template inside your Laravel application.

sending-password-reset-notifications-laravel-notification-ID

Step 4: Write Laravel code using the Courier PHP SDK

For the purposes of this demonstration, we will trigger the Courier API from an HTTP controller. In production, you will most likely want to adapt this code to send from a custom notification channel or using a queued job.

Controller

Create a new controller in your Laravel project called NotificationController:

Add the following code to this controller:

Replace <YOUR_COURIER_AUTH_TOKEN> with your Courier API key, which you can find in the Courier app by navigating to SettingsAPI Keys. Note that it is bad security practice to store an authorization token in a controller — this should only be done for testing purposes, and you should not store these credentials in source control. You should instead store tokens and credentials as environment variables and access them via the Laravel config.

sending-password-reset-notifications-with-laravel-1

Replace <NOTIFICATION_ID> with your template ID, which is in your notification template settings, as described above.

The data object should contain the variables that are used in the template. In this tutorial, our template contains three variables — userName, passwordResetLink, and companyName — however, you can include any variables you like, providing you set them in the data object in your code:

Replace <USER_NAME> with Max Overdrive, <RESET_PASSWORD_LINK> with http://example.com/reset, and <COMPANY_NAME> with ACME Inc.

Finally, replace <RECEIVER_EMAIL> with your own email address, so that when you run your Laravel code, you can verify the email was sent to you.

Route

Configure the Laravel route for your notifications by navigating to the routes/api.php file in your Laravel project and configure a new route for your NotificationController’s password-reset request:

Step 5: Run your code to send the password reset notification

Run your Laravel application with the php artisan serve command. By default, your Laravel app is served on HTTP port 8000.

Now, send a GET request to your password reset URL by entering the following address into your browser:

Or use curl to test from the command line:

This should cause the password email to be sent. If you ensure that the value of the email key in the Laravel code is your own email address, you can test that the email is sent to you. If successful you will see a JSON response resembling:

If you receive an error, you will receive a message to assist with debugging.

Check your email inbox, and you should find the password reset notification there.

sending-password-reset-notifications-with-laravel-5

Step 6: Verify that your notifications were sent

When you’re testing your code by sending an email to yourself, it’s easy to be sure whether the notification was sent or not. But if you want to check if an email was sent to a user, you will need to check the Courier logs.

Navigate to the Logs page in the Courier app. You'll see a list of all notifications sent from your account, with their status, including whether each one was sent, delivered, opened, or clicked, or whether there were any errors with sending.

sending-password-reset-notifications-with-laravel-9

Conclusion

This tutorial covered how to integrate the sending of password reset notifications in Courier into your Laravel codebase, using the Courier PHP SDK. You can use this same technique for sending other kinds of notifications in Courier such as welcome emails, shopping cart abandonment notifications, and order confirmation emails.

You can also use the Courier PHP SDK to interact with almost anything you might want to do in Courier, including updating notification preferences, invoking automations, or updating audiences.

Please contact us if you want to further discuss your project and unique requirements.

Get started sending notifications with Courier in minutes, not days!

We have SDKs in Ruby, Go, Python, Javascript, Node.js, and React.

Sign up

More from Tutorial

How to set up automatic push notifications based on Segment events thumbnail
TUTORIAL

How to Set Up Automatic Push Notifications Based on Segment Events

Push notifications have carved their own niche as a powerful tool for continuous user engagement. Regardless of whether an app is actively in use, they deliver your messages straight to your user's device. Two key players that can combine to enhance your push notification strategy are Segment and Courier. In this tutorial, we show you how to set up Courier to listen to your Segment events and then send push notifications to an Android device based on data from these events.

Sarah Barber

Sarah Barber

November 17, 2023

image14
TUTORIAL

How to Send Firebase Notifications to iOS Devices Using Courier

This tutorial explains how to send push notifications to iOS devices from your iOS application code using Firebase FCM and Courier’s iOS SDK.

Martina Caccamo

Martina Caccamo

November 01, 2023

Build your first notification in minutes

Send up to 10,000 notifications every month, for free.

Get started for free

Email & push notification

Build your first notification in minutes

Send up to 10,000 notifications every month, for free.

Get started for free

Email & push notification

Platform

Users

Content

Channels

Sending

Workflows

Preferences

Inbox

Workspaces

Observability

API Status

Changelog

© 2024 Courier. All rights reserved.