PHPackages                             spencer14420/sp-php-email-handler - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Mail &amp; Notifications](/categories/mail)
4. /
5. spencer14420/sp-php-email-handler

ActiveLibrary[Mail &amp; Notifications](/categories/mail)

spencer14420/sp-php-email-handler
=================================

A server-side PHP handler for contact forms. Handles form submissions, validates user inputs, sends emails to a mailbox, and sends confirmation emails to users.

1.0.1(1y ago)0546[1 issues](https://github.com/Spencer14420/SPEmailHandler-PHP/issues)[3 PRs](https://github.com/Spencer14420/SPEmailHandler-PHP/pulls)MITPHPCI passing

Since Nov 12Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/Spencer14420/SPEmailHandler-PHP)[ Packagist](https://packagist.org/packages/spencer14420/sp-php-email-handler)[ RSS](/packages/spencer14420-sp-php-email-handler/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (8)Dependencies (3)Versions (17)Used By (0)Security (1)

SP PHP Email Handler
====================

[](#sp-php-email-handler)

A PHP package for handling contact form submissions. Features include:

- **Email delivery**: Sends messages to both the recipient mailbox and confirmation emails to the sender.
- **Captcha verification**: Supports Google reCAPTCHA, Cloudflare Turnstile, or custom captchas.
- **CSRF protection**: Validates requests using anti-CSRF tokens.
- **JSON error responses**: Provides standardized error messages with appropriate HTTP status codes.

Requirements
------------

[](#requirements)

- PHP 7.4 or higher
- A configured `config.php` file with required variables (see "Configuration" below)

All required libraries are bundled with this package, including:

- [PHPMailer](https://github.com/PHPMailer/PHPMailer) for email sending
- [spencer14420\\SpAntiCsrf](https://github.com/spencer14420/SPAntiCSRF) for CSRF protection

Installation
------------

[](#installation)

1. Install the package via Composer:

    ```
    composer require spencer14420/sp-php-email-handler
    ```
2. Include the `autoload.php` file in your project:

    ```
    require_once 'vendor/autoload.php';
    ```

Usage
-----

[](#usage)

### Initialization

[](#initialization)

```
use spencer14420\PhpEmailHandler\EmailHandler;

$emailHandler = new EmailHandler('/path/to/config.php');
```

### Handling Requests

[](#handling-requests)

```
$emailHandler->handleRequest();
```

### Example Contact Form

[](#example-contact-form)

```

  Send

```

### Example `email-handler.php`

[](#example-email-handlerphp)

```
require_once 'vendor/autoload.php';

use spencer14420\PhpEmailHandler\EmailHandler;

try {
    $emailHandler = new EmailHandler('/path/to/config.php');
    $emailHandler->handleRequest();
} catch (Exception $e) {
    http_response_code(500);
    echo json_encode(['status' => 'error', 'message' => $e->getMessage()]);
}
```

Configuration
-------------

[](#configuration)

Create a `config.php` file with the following variables:

```
#### REQUIRED ####

$mailboxEmail = 'your-mailbox@example.com';
// The email address where messages from the contact form will be sent.
// This must be provided and must be a valid email address.

#### OPTIONAL ####

$fromEmail = 'no-reply@example.com';
// The email address used as the "From" address in outgoing emails.
// If not provided, it defaults to the `$mailboxEmail`.

$replyToEmail = 'support@example.com';
// The email address used as the "Reply-To" address in outgoing emails.
// If not provided, it defaults to the `$mailboxEmail`.

$siteDomain = 'example.com';
// The domain name of the website (e.g., example.com).
// If not provided, it defaults to the server's host name (`$_SERVER['HTTP_HOST']`).

$siteName = 'Example';
// The name of the website, used in email subjects and greetings.
// If not provided, it is derived from `$siteDomain` (e.g., "Example" for "example.com").

$captchaToken = '';
// If using a CAPTCHA, this should be set to the POST variable containing the CAPTCHA token.
// If CAPTCHA is not used, leave this empty.

$captchaSecret = '';
// The secret key for verifying CAPTCHA responses, required if CAPTCHA is enabled.
// If CAPTCHA is not used, leave this empty.

$captchaVerifyURL = '';
// The URL used to verify the CAPTCHA response.
// e.g. https://www.google.com/recaptcha/api/siteverify

$checkCsrf = false;
// Set to `true` to enable CSRF protection or `false` to disable it.

$csrfToken = '';
// The CSRF token from the POST request. Required if `$checkCsrf` is set to `true`.
```

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance69

Regular maintenance activity

Popularity12

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 78.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~2 days

Total

8

Last Release

528d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5ce8c44809b4e4b6a35724c59ea2b6a55e40922934d717894de9d8edd1d9cc31?d=identicon)[Spencer14420](/maintainers/Spencer14420)

---

Top Contributors

[![Spencer14420](https://avatars.githubusercontent.com/u/67592325?v=4)](https://github.com/Spencer14420 "Spencer14420 (18 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (5 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/spencer14420-sp-php-email-handler/health.svg)

```
[![Health](https://phpackages.com/badges/spencer14420-sp-php-email-handler/health.svg)](https://phpackages.com/packages/spencer14420-sp-php-email-handler)
```

###  Alternatives

[ivantcholakov/codeigniter-phpmailer

A CodeIgniter 3 compatible email-library powered by PHPMailer.

25313.9k](/packages/ivantcholakov-codeigniter-phpmailer)[markguinn/silverstripe-email-helpers

Silverstripe extension containing SMTP mailer class and some other classes for HTML emails

3145.4k1](/packages/markguinn-silverstripe-email-helpers)[msp/smtp

SMTP with PHPMailer

2129.4k](/packages/msp-smtp)[nfephp-org/sped-mail

API para geração e envio dos emails relacionados com o SPED.

1123.7k](/packages/nfephp-org-sped-mail)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
