PHPackages                             smtp2go-oss/smtp2go-php - 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. smtp2go-oss/smtp2go-php

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

smtp2go-oss/smtp2go-php
=======================

A library for sending email through the SMTP2GO Api

1.2.0(1mo ago)1330.9k↓23.6%12MITPHPPHP &gt;=7.4.0

Since Jul 21Pushed 1w ago4 watchersCompare

[ Source](https://github.com/smtp2go-oss/smtp2go-php)[ Packagist](https://packagist.org/packages/smtp2go-oss/smtp2go-php)[ RSS](/packages/smtp2go-oss-smtp2go-php/feed)WikiDiscussions development Synced yesterday

READMEChangelogDependencies (7)Versions (21)Used By (2)

SMTP2GO PHP API
===============

[](#smtp2go-php-api)

This library provides a simple way to send email via the SMTP2GO API and also access other endpoints in the API in a standard way.

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

[](#requirements)

- PHP &gt;= 7.4
- [Guzzle](https://github.com/guzzle/guzzle) ^7.0 (installed automatically via Composer)

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

[](#installation)

```
composer require smtp2go-oss/smtp2go-php

```

You can obtain an API key from [app.smtp2go.com/settings/apikeys](https://app-us.smtp2go.com/sending/apikeys/).

Examples
--------

[](#examples)

### Sending an Email

[](#sending-an-email)

```
use SMTP2GO\ApiClient;
use SMTP2GO\Service\Mail\Send as MailSend;
use SMTP2GO\Types\Mail\Address;
use SMTP2GO\Collections\Mail\AddressCollection;
use SMTP2GO\Collections\Mail\AttachmentCollection;
use SMTP2GO\Types\Mail\FileAttachment;
use SMTP2GO\Types\Mail\InlineAttachment;
use SMTP2GO\Types\Mail\CustomHeader;

$message = addAddress('cc', new Address('cc@email.test'));
$sendService->addAddress('bcc', new Address('bcc@email.test'));

$sendService->setAttachments(new AttachmentCollection([ new FileAttachment('attachment-data','file1.txt'), new FileAttachment('another-attachment-data','file2.txt')]));

$inline = new InlineAttachment('a-cat-picture', file_get_contents('attachments/cat.jpg'), 'image/jpeg');

$sendService->addAttachment($inline);

$sendService->addCustomHeader(new CustomHeader('Reply-To', 'replyto@email.test'));

$apiClient = new ApiClient('api-YOURAPIKEY');

#set a custom region
$apiClient->setApiRegion('us');

#set the client to retry using a different server ip if possible
$apiClient->setMaxSendAttempts(5);

#set the number of seconds to increase the request timeout with each attempt
$apiClient->setTimeoutIncrement(5);

$success = $apiClient->consume($sendService);

$responseBody = $apiClient->getResponseBody();
```

### Handling the Response

[](#handling-the-response)

`consume()` returns `true` if the API responded with HTTP 200, `false` otherwise. Use the response methods to inspect the result or diagnose failures:

```
$success = $apiClient->consume($sendService);

if ($success) {
    $body = $apiClient->getResponseBody(); // stdClass
    echo $body->data->succeeded; // number of messages queued
} else {
    $body = $apiClient->getResponseBody();
    echo $body->data->error;      // human-readable error message
    echo $body->data->error_code; // machine-readable error code

    // If an exception was thrown (e.g. connection failure):
    echo $apiClient->getLastRequest();          // the outgoing request as a string
    echo $apiClient->getLastResponseStatusCode(); // HTTP status code, or null
}
```

To get the raw response headers:

```
$headers = $apiClient->getResponseHeaders(); // array
```

### Scheduling an Email

[](#scheduling-an-email)

Pass a Unix timestamp up to 3 days in the future to `scheduleAt()`:

```
$sendService->scheduleAt(strtotime('+2 hours'));
$apiClient->consume($sendService);
```

### Retry / Failover`

[](#retry--failover)

When `setMaxSendAttempts()` is greater than 1, the client will automatically resolve alternative IP addresses for `api.smtp2go.com` and retry failed requests against them, increasing the timeout by `setTimeoutIncrement()` seconds on each attempt. Useful for high-reliability sending. Requires ext-curl.

```
$apiClient->setMaxSendAttempts(5);   // try up to 5 different IPs
$apiClient->setTimeoutIncrement(5);  // add 5 seconds to timeout per attempt
```

After a failed send you can inspect what happened:

```
foreach ($apiClient->getFailedAttemptInfo() as $attempt) {
    echo $attempt['ip'];    // IP that was tried
    echo $attempt['error']; // exception message
}
echo $apiClient->getFailedAttempts(); // total number of failed attempts
```

### Attachments

[](#attachments)

**`FileAttachment`** - attach a file by passing its raw content and a filename. The MIME type is detected automatically from the filename extension:

```
use SMTP2GO\Types\Mail\FileAttachment;
use SMTP2GO\Collections\Mail\AttachmentCollection;

$sendService->setAttachments(new AttachmentCollection([
    new FileAttachment(file_get_contents('/path/to/report.pdf'), 'report.pdf'),
]));
```

**`InlineAttachment`** - embed an image directly in the HTML body using a content ID:

```
use SMTP2GO\Types\Mail\InlineAttachment;

// Reference in your HTML as:
$inline = new InlineAttachment('my-image', file_get_contents('/path/to/image.jpg'), 'image/jpeg');
$sendService->addAttachment($inline);
```

### Custom Headers

[](#custom-headers)

```
use SMTP2GO\Types\Mail\CustomHeader;

$sendService->addCustomHeader(new CustomHeader('Reply-To', 'replyto@email.test'));
$sendService->addCustomHeader(new CustomHeader('X-Mailer', 'MyApp'));
```

### Sending email using a template

[](#sending-email-using-a-template)

This sample code is for the example template "User Welcome"

```
use SMTP2GO\ApiClient;
use SMTP2GO\Types\Mail\Address;
use SMTP2GO\Service\Mail\Send as MailSend;
use SMTP2GO\Collections\Mail\AddressCollection;

$client = new ApiClient('api-YOURAPIKEY');
$sendService = new MailSend(
    new Address('sender@site.test', 'Sender Name'),
    new AddressCollection([
        new Address('recipient@example.test', 'Bob Recipient'),
    ]),
    '', //subject is empty as this is defined in the template
    '', //body is empty as this is generated from the template
);
$sendService->setTemplateId(6040276);
$sendService->setTemplateData([
    "username" => "Steve",
    "product_name" => "Widgets",
    "action_url" => "https://website.localhost",
    "login_url" => "https://website.localhost/login",
    "guide_url" => "https://website.localhost/guide",
    "support_email" => "support@website.localhost",
    "sender_name" => "Bob Widgets"
]);

$res = $client->consume($sendService);
```

### Consuming an endpoint in the API using the Service class

[](#consuming-an-endpoint-in-the-api-using-the-service-class)

```
use SMTP2GO\ApiClient;
use SMTP2GO\Service\Service;

$client = new ApiClient('api-YOURAPIKEY');

$success = $client->consume((new Service('domain/verify', ['domain' => 'mydomain.tld'])));
```

License
-------

[](#license)

The package is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).

###  Health Score

56

—

FairBetter than 97% of packages

Maintenance95

Actively maintained with recent releases

Popularity37

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 90.4% 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 ~103 days

Recently: every ~131 days

Total

18

Last Release

42d ago

PHP version history (2 changes)1.0.0betaPHP &gt;=7.2.0

1.1.4PHP &gt;=7.4.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/13650641?v=4)[CodaKris](/maintainers/CodaKris)[@CodaKris](https://github.com/CodaKris)

---

Top Contributors

[![CodaKris](https://avatars.githubusercontent.com/u/13650641?v=4)](https://github.com/CodaKris "CodaKris (123 commits)")[![markcollister](https://avatars.githubusercontent.com/u/1679883?v=4)](https://github.com/markcollister "markcollister (10 commits)")[![szepeviktor](https://avatars.githubusercontent.com/u/952007?v=4)](https://github.com/szepeviktor "szepeviktor (3 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/smtp2go-oss-smtp2go-php/health.svg)

```
[![Health](https://phpackages.com/badges/smtp2go-oss-smtp2go-php/health.svg)](https://phpackages.com/packages/smtp2go-oss-smtp2go-php)
```

###  Alternatives

[aws/aws-sdk-php

AWS SDK for PHP - Use Amazon Web Services in your PHP project

6.3k543.5M2.6k](/packages/aws-aws-sdk-php)[pimcore/pimcore

Content &amp; Product Management Framework (CMS/PIM/E-Commerce)

3.8k3.8M508](/packages/pimcore-pimcore)[matomo/matomo

Matomo is the leading Free/Libre open analytics platform

21.7k38.9k](/packages/matomo-matomo)[neuron-core/neuron-ai

The PHP Agentic Framework.

2.0k656.1k38](/packages/neuron-core-neuron-ai)[tencentcloud/tencentcloud-sdk-php

TencentCloudApi php sdk

3741.3M47](/packages/tencentcloud-tencentcloud-sdk-php)[tempest/framework

The PHP framework that gets out of your way.

2.2k34.4k15](/packages/tempest-framework)

PHPackages © 2026

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