spencer14420/sp-php-email-handler 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

spencer14420/sp-php-email-handler

Composer 安装命令:

composer require 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.

README 文档

README

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

  • 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:

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

Initialization

use spencer14420\PhpEmailHandler\EmailHandler;

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

Handling Requests

$emailHandler->handleRequest();

Example Contact Form

<form action="/path/to/email-handler.php" method="POST">
  <input type="hidden" name="csrfToken" value="your-csrf-token" />
  <input type="email" name="email" placeholder="Your Email" required />
  <input type="text" name="name" placeholder="Your Name" required />
  <textarea name="message" placeholder="Your Message" required></textarea>
  <button type="submit">Send</button>
</form>

Example email-handler.php

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

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`.

spencer14420/sp-php-email-handler 适用场景与选型建议

spencer14420/sp-php-email-handler 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 547 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 11 月 12 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 spencer14420/sp-php-email-handler 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 spencer14420/sp-php-email-handler 我们能提供哪些服务?
定制开发 / 二次开发

基于 spencer14420/sp-php-email-handler 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 547
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 28
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-11-12