PHPackages                             landlib/simplemail - 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. landlib/simplemail

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

landlib/simplemail
==================

Reliable and comfortable mail sending with PHP mail() use gmail.com. Attachment support. Надёжная и удобная отправка писем with gmail.com. Вложения поддерживаются.

09PHP

Since Dec 14Pushed 3y ago1 watchersCompare

[ Source](https://github.com/lamzin-andrey/simplemail)[ Packagist](https://packagist.org/packages/landlib/simplemail)[ RSS](/packages/landlib-simplemail/feed)WikiDiscussions master Synced 4d ago

READMEChangelogDependenciesVersions (1)Used By (0)

#### Content / Содержание

[](#content--содержание)

[Ru](#ru)

[En](#en)

En
==

[](#en)

#### Content

[](#content)

[About](#about)

[Installation](#installation)

[Usage on product server](#usage-on-product-server)

[Usage on localhost linux ubuntu and gmail service](#usage-on-localhost-linux-ubuntu-and-gmail-service)

About
-----

[](#about)

This reliable and comfortable send email class with attachment support using PHP mail() function. I use it PHP class last ten years and I see, than it more reliable then Swift\_Mailer and Symfony Mailer email tools.

It is not modest, but I will write. In November 2019 I created Symfony 3.4 project, it use gmail service on my localhost and hosting provider mailbox in production site.

03 January 2020 year I find, that suddenly emails stopped sending from my localhost (I use gmail account and ssmtp). There were no errors in the logs of Symphonies 3.4.

I do not edited my Symfony scripts.

I try send email from Symfony 5.0.2 project, but got error "Exception occurred while flushing email queue: Connection could not be established with host smtp.gmail.com :stream\_socket\_client(): SSL operation failed with code 1. OpenSSL Error messages: error:1416F086:SSL routines:tls\_process\_server\_certificate:certificate verify failed".

I try send email use my class SimpleMail - and it was successfull.

I many used this script, on different php hostings. It realy is working (for example - one from first my commits with it class here ).

Therefore I public this PHP class, I hope that will helpfull for you too.

Happy New Year and Merry Christmas.

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

[](#installation)

`composer require landlib/simplemail`

or

`git clone https://github.com/lamzin-andrey/simplemail`

Usage on product server
-----------------------

[](#usage-on-product-server)

### Configure mailbox in ISP Manager on your hosting provider

[](#configure-mailbox-in-isp-manager-on-your-hosting-provider)

Create mailbox using ISP Manager interface. Will be sure, than you can send email from it use RoundCude or other interface.

### Example

[](#example)

```
use Landlib\SimpleMail;

//Simple email
$sender = 'yoursendmailbox@yoursite.com';
$recipient = 'yourothermailbox@gmail.com';
$mailer = new SimpleMail();
$mailer->setSubject('It test package landlib/simplemail');
$mailer->setFrom($sender, 'Your name');
$mailer->setTo($recipient);
$mailer->setBody('Hello, my friend', 'text/html', 'UTF-8');
$r = $mailer->send();
var_dump($r);

//Mail with attach
$mailer->setSubject('It test package landlib/simplemail - mail with inline attachment');
$mailer->setTextWithImages('Hello, my friend, {smile}!' . "\nI am a very satisfied person!", ['{smile}' => __DIR__ . '/smile.png']);
$r = $mailer->send();
var_dump($r);
```

Usage on localhost linux ubuntu and gmail service
-------------------------------------------------

[](#usage-on-localhost-linux-ubuntu-and-gmail-service)

It for linux ubuntu Desktop users.

### Create gmail account and allow access for unsafe applications

[](#create-gmail-account-and-allow-access-for-unsafe-applications)

On 03 01 2020 it possible on link

If link do not work, configure your ssmtp (see [Configure ssmtp](#instal-and-configure-ssmtp-server)) and try run example script app.php.

```
php app.php
```

You can see text like this:

```
ssmtp: Authorization failed (535 5.7.8  https://support.google.com/mail/?p=BadCredentials h7sm24406885lfj.29 - gsmtp)
/opt/lampp/htdocs/mh.loc/www/q/q/simplemail/example/app.php:31:
bool(false)
```

Goto link from message and see support page - it containts link to settings page, where you can set allow access unsafe applications.

### Instal and configure ssmtp server

[](#instal-and-configure-ssmtp-server)

It for linux ubuntu Desktop users.

```
sudo apt-get install ssmtp
```

Let your gmail address will `testshop@gmail.com`.

Open file `/etc/ssmtp/revaliases`

```
sudo gedit /etc/ssmtp/revaliases
```

Set string

```
root:testshop@gmail.com:smtp.gmail.com:587
```

Open file `/etc/ssmtp/ssmtp.conf`

```
sudo gedit /etc/ssmtp/ssmtp.conf
```

Set content

```
root=testshop@gmail.com
mailhub=smtp.gmail.com:587
hostname=smtp.gmail.com:587
UseSTARTTLS=YES
AuthUser=testshop@gmail.com
AuthPass=***** #your password must be here
FromLineOverride=YES
```

Open your php.ini file (I use XAMPP, my php.ini location is `/opt/lampp/etc/php.ini`)

and add (or replace) string

```
sendmail_path = /usr/sbin/ssmtp -t
```

Restart your apache server (I use XAMPP, therefore run `/opt/lampp/lampp restart`)

Run example script app.php (see [Create gmail account section](#create-gmail-account-and-allow-access-for-unsafe-applications))

Ru
==

[](#ru)

#### Содержание

[](#содержание)

[Что это](#%D1%87%D1%82%D0%BE-%D1%8D%D1%82%D0%BE)

[Установка](#%D1%83%D1%81%D1%82%D0%B0%D0%BD%D0%BE%D0%B2%D0%BA%D0%B0)

[Использование на продакшене](#%D0%B8%D1%81%D0%BF%D0%BE%D0%BB%D1%8C%D0%B7%D0%BE%D0%B2%D0%B0%D0%BD%D0%B8%D0%B5-%D0%BD%D0%B0-%D0%BF%D1%80%D0%BE%D0%B4%D0%B0%D0%BA%D1%88%D0%B5%D0%BD%D0%B5)

[Использование на локальном хосте Linux Ubuntu и службы Gmail](#%D0%B8%D1%81%D0%BF%D0%BE%D0%BB%D1%8C%D0%B7%D0%BE%D0%B2%D0%B0%D0%BD%D0%B8%D0%B5-%D0%BD%D0%B0-%D0%BB%D0%BE%D0%BA%D0%B0%D0%BB%D1%8C%D0%BD%D0%BE%D0%BC-%D1%85%D0%BE%D1%81%D1%82%D0%B5-linux-ubuntu-%D0%B8-%D1%81%D0%BB%D1%83%D0%B6%D0%B1%D1%8B-gmail)

Что это
-------

[](#что-это)

Это надежный и удобный класс для отправки электронной почты с поддержкой вложений с помощью функции PHP mail(). Я использую этот класс PHP последние десять лет и вижу, что он более надежен, чем инструменты электронной почты Swift\_Mailer и Symfony Mailer.

Это звучит нескромно, но я напишу почему я так считаю.

В ноябре 2019 года я создал проект Symfony 3.4, он использует службу gmail на моем локальном хосте и почтовый ящик хостинг-провайдера на продакшене.

03 января 2020 года я обнаружил, что внезапно письма перестали отправляться с моего локального хоста (я использую учетную запись gmail и ssmtp). В логах Symfony 3.4 ошибок не было.

Я не редактировал свои скрипты Symfony.

Я попытался отправить письмо из проекта Symfony 5.0.2, но получил ошибку "Exception occurred while flushing email queue: Connection could not be established with host smtp.gmail.com :stream\_socket\_client(): SSL operation failed with code 1. OpenSSL Error messages: error:1416F086:SSL routines:tls\_process\_server\_certificate:certificate verify failed".

Тогда я попытался отправить электронную почту, используя мой класс SimpleMail - и это было успешно.

Я много использовал этот скрипт раньше, на разных хостингах php. Это действительно работает (например, один из первых моих коммитов с этим классом здесь ).

Поэтому я публикую этот класс PHP, я надеюсь, что он вам пригодится.

С Новым годом и Рождеством.

Установка
---------

[](#установка)

`composer require landlib/simplemail`

или

`git clone https://github.com/lamzin-andrey/simplemail`

Использование на продакшене
---------------------------

[](#использование-на-продакшене)

### Настройте почтовый ящик в ISP Manager на хостинг-провайдере

[](#настройте-почтовый-ящик-в-isp-manager-на-хостинг-провайдере)

Создайте почтовый ящик с помощью интерфейса ISP Manager. Убедитесь, что вы можете отправить письмо с него, используя RoundCude или другой интерфейс.

### Пример кода

[](#пример-кода)

```
use Landlib\SimpleMail;

//Простой email
$sender = 'yoursendmailbox@yoursite.com';
$recipient = 'yourothermailbox@gmail.com';
$mailer = new SimpleMail();
$mailer->setSubject('It test package landlib/simplemail');
$mailer->setFrom($sender, 'Your name');
$mailer->setTo($recipient);
$mailer->setBody('Hello, my friend', 'text/html', 'UTF-8');
$r = $mailer->send();
var_dump($r);

//Письмо с вложением
$mailer->setSubject('It test package landlib/simplemail - mail with inline attachment');
$mailer->setTextWithImages('Hello, my friend, {smile}!' . "\nI am a very satisfied person!", ['{smile}' => __DIR__ . '/smile.png']);
$r = $mailer->send();
var_dump($r);
```

Использование на локальном хосте Linux Ubuntu и службы Gmail
------------------------------------------------------------

[](#использование-на-локальном-хосте-linux-ubuntu-и-службы-gmail)

Это для пользователей Linux Ubuntu Desktop.

### Создать учетную запись Gmail и разрешить доступ для небезопасных приложений

[](#создать-учетную-запись-gmail-и-разрешить-доступ-для-небезопасных-приложений)

На 03 01 2020 это возможно по ссылке

Если ссылка не работает, настройте ssmtp (см. [Настройка ssmtp](#%D1%83%D1%81%D1%82%D0%B0%D0%BD%D0%BE%D0%B2%D0%B8%D1%82%D1%8C-%D0%B8-%D0%BD%D0%B0%D1%81%D1%82%D1%80%D0%BE%D0%B8%D1%82%D1%8C-%D1%81%D0%B5%D1%80%D0%B2%D0%B5%D1%80-ssmtp)) и попробуйте запустить пример сценария app.php из папки example.

```
php app.php
```

Вы можете увидеть текст похожий на этот:

```
ssmtp: Authorization failed (535 5.7.8  https://support.google.com/mail/?p=BadCredentials h7sm24406885lfj.29 - gsmtp)
/opt/lampp/htdocs/mh.loc/www/q/q/simplemail/example/app.php:31:
bool(false)
```

Переходите по ссылке из сообщения и смотрите страницу поддержки - она содержит ссылку на страницу настроек, где вы можете разрешить доступ небезопасных приложений.

### Установить и настроить сервер ssmtp

[](#установить-и-настроить-сервер-ssmtp)

Это для пользователей Linux Ubuntu Desktop.

```
sudo apt-get install ssmtp
```

Например ваш адрес `testshop@gmail.com`.

Откройте файл `/etc/ssmtp/revaliases`

```
sudo gedit /etc/ssmtp/revaliases
```

Добавьте строку

```
root:testshop@gmail.com:smtp.gmail.com:587
```

Откройте файл `/etc/ssmtp/ssmtp.conf`

```
sudo gedit /etc/ssmtp/ssmtp.conf
```

Замените содержимое

```
root=testshop@gmail.com
mailhub=smtp.gmail.com:587
hostname=smtp.gmail.com:587
UseSTARTTLS=YES
AuthUser=testshop@gmail.com
AuthPass=***** #здесь должен быть ваш пароль, кавычки не нужны
FromLineOverride=YES
```

Откройте ваш php.ini file (Я использую XAMPP, мой php.ini находится `/opt/lampp/etc/php.ini`)

и добавьте или отредактируйте строку

```
sendmail_path = /usr/sbin/ssmtp -t
```

Рестартуйте apache (Я использую XAMPP, поэтому запускаю `sudo /opt/lampp/lampp restart`)

Запустите пример скрипта app.php (смотрите раздел [Создать учетную запись Gmail и разрешить доступ для небезопасных приложений](#%D1%81%D0%BE%D0%B7%D0%B4%D0%B0%D1%82%D1%8C-%D1%83%D1%87%D0%B5%D1%82%D0%BD%D1%83%D1%8E-%D0%B7%D0%B0%D0%BF%D0%B8%D1%81%D1%8C-gmail-%D0%B8-%D1%80%D0%B0%D0%B7%D1%80%D0%B5%D1%88%D0%B8%D1%82%D1%8C-%D0%B4%D0%BE%D1%81%D1%82%D1%83%D0%BF-%D0%B4%D0%BB%D1%8F-%D0%BD%D0%B5%D0%B1%D0%B5%D0%B7%D0%BE%D0%BF%D0%B0%D1%81%D0%BD%D1%8B%D1%85-%D0%BF%D1%80%D0%B8%D0%BB%D0%BE%D0%B6%D0%B5%D0%BD%D0%B8%D0%B9))

###  Health Score

14

—

LowBetter than 2% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity24

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/0c515a68fa757958c4b37cf7c3083ad210d9be2a6059b7a255bd8c23856abfe0?d=identicon)[lamzin](/maintainers/lamzin)

---

Top Contributors

[![lamzin-andrey](https://avatars.githubusercontent.com/u/7406021?v=4)](https://github.com/lamzin-andrey "lamzin-andrey (7 commits)")

### Embed Badge

![Health badge](/badges/landlib-simplemail/health.svg)

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

###  Alternatives

[tijsverkoyen/css-to-inline-styles

CssToInlineStyles is a class that enables you to convert HTML-pages/files into HTML-pages/files with inline styles. This is very useful when you're sending emails.

5.8k505.3M227](/packages/tijsverkoyen-css-to-inline-styles)[minishlink/web-push

Web Push library for PHP

1.9k12.0M53](/packages/minishlink-web-push)[laravel-notification-channels/twilio

Provides Twilio notification channel for Laravel

2587.7M12](/packages/laravel-notification-channels-twilio)[spatie/url-signer

Generate a url with an expiration date and signature to prevent unauthorized access

4422.3M16](/packages/spatie-url-signer)[mattketmo/email-checker

Throwaway email detection library

2742.0M5](/packages/mattketmo-email-checker)[laravel-notification-channels/discord

Laravel notification driver for Discord.

2371.3M11](/packages/laravel-notification-channels-discord)

PHPackages © 2026

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