PHPackages                             onviser/mailer - 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. onviser/mailer

ActiveLibrary

onviser/mailer
==============

PHP library for sending email with attachments over SMTP

1.0.4(5mo ago)09Apache-2.0PHPPHP &gt;=8.3

Since Feb 29Pushed 5mo agoCompare

[ Source](https://github.com/onviser/mailer)[ Packagist](https://packagist.org/packages/onviser/mailer)[ RSS](/packages/onviser-mailer/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (2)Versions (5)Used By (0)

PHP library for sending email with attachments over SMTP
========================================================

[](#php-library-for-sending-email-with-attachments-over-smtp)

Simple sending of emails via socket. Convenient to use on shared hosting, where there are problems with using PHP mail() function.

Install
-------

[](#install)

```
composer require onviser/mailer
```

How to use
----------

[](#how-to-use)

Sending simple email:

```
$mail = (new Mail())
            ->setSubject('This is a subject')
            ->setBody('This is a body')
            ->setFrom('from@example.com')
            ->to('to@example.com');

$socket = new Socket('localhost', 25, 'login', 'password');
$mailer = new SendToSocketMailer($socket);
if ($mailer->send($mail)) {
    // mail was sent
} else { // error
    echo "error: {$mailer->getError()}" . PHP_EOL;
    print_r($mailer->getLog());
}
```

Email with copy and blind copy:

```
$mail = (new Mail())
            ->setSubject('This is a subject')
            ->setBody('This is a body')
            ->setFrom('from@example.com')
            ->to('to1@example.com')
            ->to('to2@example.com')
            ->copy('copy1@example.com')
            ->copy('copy2@example.com')
            ->blindCopy('blind-copy@example.com');
```

Email with "Reply-To" header:

```
$mail = (new Mail())
            ->setSubject('This is a subject')
            ->setBody('This is a body')
            ->setFrom('from@example.com')
            ->setReplayTo('replay-to@example.com')
            ->to('to@example.com');
```

Email with attachments:

```
$attachmentText = (new Attachment())
                    ->setFileName('file.txt')
                    ->setFileType('text/plain')
                    ->setData('This is a text.');
$attachmentHTML = (new Attachment())
                    ->setFileName('file.html')
                    ->setFileType('text/html')
                    ->setData('This is a HTML.');
$mail = (new Mail())
            ->setType(Mail::TYPE_HTML)
            ->setSubject('This is a subject')
            ->setBody('This is a HTML body')
            ->setFrom('from@example.com')
            ->to('to@example.com')
            ->attachment($attachmentText)
            ->attachment($attachmentHTML);
```

### Send to file (for development environment)

[](#send-to-file-for-development-environment)

During development, it is convenient to use storing emails on disk instead of sending them.

```
$mail = (new Mail())
            ->setSubject('This is a subject')
            ->setBody('This is a body')
            ->setFrom('from@example.com')
            ->to('to@example.com');

$mailer = new SendToFileMailer('../var/mail/');
if ($mailer->send($mail)) {
    // mail was saved
} else { // error
    echo "error: {$mailer->getError()}" . PHP_EOL;
}
```

Tests
-----

[](#tests)

```
./vendor/bin/phpunit
./vendor/bin/phpstan

```

PHP-библиотека для отправки электронной почты с вложениями по SMTP
==================================================================

[](#php-библиотека-для-отправки-электронной-почты-с-вложениями-по-smtp)

Простая отправка электронных писем через сокет. Удобна для использования на виртуальном хостинге, где есть проблемы с использованием функции PHP mail().

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance70

Regular maintenance activity

Popularity4

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~211 days

Total

4

Last Release

174d ago

PHP version history (2 changes)1.0.1PHP &gt;=8.2

1.0.4PHP &gt;=8.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/46e41a385837bbe98a56b0eb1780c6fcfb12420958735138e064da8f5ef1e83d?d=identicon)[onviser](/maintainers/onviser)

---

Top Contributors

[![onviser](https://avatars.githubusercontent.com/u/32374372?v=4)](https://github.com/onviser "onviser (5 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/onviser-mailer/health.svg)

```
[![Health](https://phpackages.com/badges/onviser-mailer/health.svg)](https://phpackages.com/packages/onviser-mailer)
```

PHPackages © 2026

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