PHP 3d ago 5 views 2 min read

How to send password reset emails using PHPMailer in PHP

Configure SMTP settings, compose the reset message, and deliver the email securely using PHPMailer with PHP 8.3 and Composer.

Riya K.
Updated 4h ago
Sponsored

Cloud Hosting — blazing fast websites

Fully managed cloud hosting with free SSL, auto-backups and a friendly cPanel. Built for WordPress, Laravel and custom PHP apps.

This guide shows you how to send password reset emails using PHPMailer with PHP 8.3. You will configure SMTP credentials, compose the reset message, and deliver the email securely. The steps target a standard Linux environment with PHP 8.3.x and Composer 2.7.x.

Prerequisites

  • Operating system: Ubuntu 24.04, Debian 12, or AlmaLinux 9.
  • PHP 8.3.x installed and running.
  • Composer 2.7.x installed globally.
  • A valid SMTP server account (e.g., Gmail, SendGrid, or Postmark) with app-specific password enabled.
  • SSH access to the server with sudo privileges.

Step 1: Create a project directory

Create a new directory for your PHP application and navigate into it.

mkdir password-reset-app
cd password-reset-app

Initialize a new Composer project to manage dependencies.

composer init --name="vendor/project" --description="Password reset application" --type="project"

You will see a composer.json file created in the current directory.

Step 2: Install PHPMailer via Composer

Install the latest stable version of PHPMailer using Composer. This installs the library and its dependencies automatically.

composer require phpmailer/phpmailer

Composer will output a progress bar and confirm the installation. You will see the package added to composer.json and the files placed in vendor/.

Step 3: Create the email sender script

Create a file named send-reset.php in your project root. This script will instantiate PHPMailer, configure the SMTP settings, and send the email.

touch send-reset.php

Open the file in your editor and paste the following code. Replace the placeholder values with your actual SMTP credentials.

      
Sponsored

Powerful Dedicated Servers — Linux & Windows

Bare-metal performance with SSD storage, DDoS protection and 24/7 expert support. Ideal for production workloads, databases and high-traffic sites.

Tags: phpsecurityEmailSMTPComposer
0
Was this helpful?

Related tutorials

Comments 0

Login to leave a comment.

No comments yet — be the first to share your thoughts.