PHP Apr 14, 2026 20 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 10d ago
Sponsored

Cloud VPS — scale in minutes

Instantly deploy SSD cloud VPS with guaranteed resources, snapshots and per-hour billing. Pay only for what you use.

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

Linux Dedicated Server

Rock-solid Linux dedicated servers with root access, KVM-IPMI and fully managed options. CentOS, Ubuntu, Debian, Rocky and AlmaLinux.

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.