定制 loremipsum-systems/emailit 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

loremipsum-systems/emailit

最新稳定版本:0.1.2

Composer 安装命令:

composer require loremipsum-systems/emailit

包简介

SDK for Emailit API

README 文档

README

The EmailItMailer library is a PHP wrapper for interacting with the EmailIt API, allowing you to send emails and manage sending domains effortlessly. Built on top of GuzzleHttp, this library aims to streamline the process of integrating email features into your project.

Features

  • Send emails with HTML, text, custom headers, and file attachments.
  • Retrieve a list of sending domains with pagination and filtering.
  • Fetch detailed information about a specific sending domain.

Requirements

  • PHP 8.1 or higher
  • Composer
  • Required dependencies (managed via Composer):
    • guzzlehttp/guzzle (HTTP client)
    • psr/http-client, psr/http-message, psr/http-factory
    • ralouphie/getallheaders
    • symfony/deprecation-contracts

Installation

Use Composer to install the library:

composer loremipsum-systems/emailit

Usage

Initialization

First, create a new instance of EmailItMailer by providing your API key.

use LoremIpsum\EmailIt\EmailItMailer;

$apiKey = 'your-api-key';
$emailIt = new EmailItMailer($apiKey);

Sending an Email

To send an email, use the send method. This method supports the following parameters:

  • from: Sender's email address.
  • to: Recipient's email address.
  • subject: Email subject.
  • htmlContent: (Optional) HTML email content.
  • textContent: (Optional) Plain text email content.
  • attachments: (Optional) Array of file attachments.
  • headers: (Optional) Array of custom headers.

Here’s an example:

try {
    $response = $emailIt->send(
        'sender@example.com', // Sender
        'recipient@example.com', // Recipient
        'Hello, World!', // Subject
        '<p>This is a test email</p>', // HTML Content
        'This is a test email', // Text Content
        [], // Attachments (optional)
        ['X-Custom-Header' => 'value'] // Custom Headers (optional)
    );
    print_r($response);
} catch (Exception $e) {
    echo 'Error: ' . $e->getMessage();
}

Managing Sending Domains

Get a List of Sending Domains

Retrieve a paginated list of all sending domains using the getSendingDomains method:

try {
    $domains = $emailIt->getSendingDomains(1, 10, 'example'); // Page 1, 10 results, search term "example"
    print_r($domains);
} catch (Exception $e) {
    echo 'Error: ' . $e->getMessage();
}

Fetch Details of a Sending Domain

To get detailed information about a specific sending domain, use the getSendingDomain method:

try {
    $domainDetails = $emailIt->getSendingDomain('domain-id');
    print_r($domainDetails);
} catch (Exception $e) {
    echo 'Error: ' . $e->getMessage();
}

Error Handling

All methods in the EmailItMailer class throw standard PHP Exceptions. Common reasons for exceptions include:

  • Invalid API credentials.
  • HTTP or network errors during API requests.
  • Invalid input, such as malformed attachments.

Use try...catch blocks to handle exceptions gracefully, as shown in the examples above.

Contributing

We welcome contributions to improve the library. Feel free to:

  1. Fork the repository.
  2. Submit a Pull Request (PR) with your improvements.
  3. Ensure all code changes include tests and documentation updates (if applicable).

License

This library is released under the MIT License. See the LICENSE file for details.

Support

If you encounter any issues or need further assistance, please reach out at support@example.com or open a GitHub issue.

Acknowledgments

This library leverages the following dependencies:

  • GuzzleHttp for making HTTP requests.
  • PSR request and response libraries for standardized HTTP message handling.

Notes for Developers

  • Ensure you have proper API documentation access while working with the API endpoints.
  • Always validate attachments before sending email requests to avoid errors.

统计信息

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

GitHub 信息

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

其他信息

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