PHPackages                             ay4t/php-mailer-template - 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. ay4t/php-mailer-template

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

ay4t/php-mailer-template
========================

1.0.0(3y ago)08MITHTML

Since Nov 14Pushed 11mo ago1 watchersCompare

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

READMEChangelog (2)Dependencies (2)Versions (2)Used By (0)

PHP Email HTML Template Library
===============================

[](#php-email-html-template-library)

[![License](https://camo.githubusercontent.com/08cef40a9105b6526ca22088bc514fbfdbc9aac1ddbf8d4e6c750e3a88a44dca/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d626c75652e737667)](LICENSE)

Library PHP untuk mengirim email dengan dukungan template HTML menggunakan PHPMailer dan Twig. Library ini memudahkan pengiriman email dengan tampilan profesional menggunakan template HTML yang dapat disesuaikan.

Daftar Isi
----------

[](#daftar-isi)

- [Fitur](#fitur)
- [Persyaratan](#persyaratan)
- [Instalasi](#instalasi)
- [Konfigurasi](#konfigurasi)
- [Penggunaan Dasar](#penggunaan-dasar)
- [Template Email](#template-email)
- [Mengirim Email dengan Attachment](#mengirim-email-dengan-attachment)
- [API Referensi](#api-referensi)
- [Kontribusi](#kontribusi)
- [Lisensi](#lisensi)

Fitur
-----

[](#fitur)

- Integrasi dengan PHPMailer untuk pengiriman email yang handal
- Dukungan template HTML menggunakan Twig
- Konfigurasi SMTP yang fleksibel
- Kemampuan untuk mengirim email dengan file attachment dan string attachment
- Dukungan untuk CC dan BCC
- Metode fluent interface untuk kemudahan penggunaan

Persyaratan
-----------

[](#persyaratan)

- PHP 7.4 atau lebih tinggi
- Composer

Instalasi
---------

[](#instalasi)

Instalasi library ini dapat dilakukan dengan mudah menggunakan Composer:

```
composer require ay4t/php-mailer-template
```

Konfigurasi
-----------

[](#konfigurasi)

Sebelum menggunakan library, Anda perlu mengatur konfigurasi SMTP. Anda dapat melakukannya dengan membuat instance konfigurasi sendiri atau menggunakan konfigurasi default.

### Menggunakan Konfigurasi Default

[](#menggunakan-konfigurasi-default)

Konfigurasi default tersedia di `src/Config/App.php`. Anda perlu mengubah nilai-nilai berikut sesuai dengan pengaturan SMTP Anda:

```
// Buat file konfigurasi kustom yang meng-extend konfigurasi default
class MyConfig extends \Ay4t\Emailhtml\Config\App
{
    public function __construct()
    {
        $this->Host = 'smtp.gmail.com';            // Server SMTP
        $this->Username = 'your-email@gmail.com';   // Username SMTP
        $this->Password = 'your-password';          // Password SMTP
        $this->Port = 465;                          // Port SMTP
        $this->FromName = 'Your Name';              // Nama pengirim
        $this->FromEmail = 'your-email@gmail.com';  // Email pengirim
        $this->template_path = '/path/to/templates'; // Path template kustom (opsional)
    }
}

// Gunakan konfigurasi kustom
$email = new \Ay4t\Emailhtml\Mailer('template_name', new MyConfig());
```

Penggunaan Dasar
----------------

[](#penggunaan-dasar)

Berikut adalah contoh penggunaan dasar untuk mengirim email:

```
// Inisialisasi mailer dengan template default
$email = new \Ay4t\Emailhtml\Mailer();

// Tambahkan data untuk template
$email->mergeData([
    'fullname'      => 'John Doe',
    'dashboard_url' => 'https://example.com/dashboard',
    'username'      => 'johndoe',
    'password'      => '123456',
]);

// Atur subjek email
$email->setSubject('Selamat Datang di Aplikasi Kami');

// Atur teks alternatif untuk klien email yang tidak mendukung HTML
$email->setAltBody('Selamat datang di aplikasi kami. Username: johndoe, Password: 123456');

// Tambahkan penerima
$email->sendTo('recipient@example.com', 'Recipient Name');

// Tambahkan CC (opsional)
$email->addCCto('cc@example.com', 'CC Recipient');

// Nonaktifkan output debug (opsional)
$email->setDebugOutput(false);

// Kirim email
$result = $email->send();

if ($result) {
    echo "Email berhasil dikirim!";
} else {
    echo "Gagal mengirim email.";
}
```

Template Email
--------------

[](#template-email)

Library ini mendukung penggunaan template HTML dengan Twig. Template default tersedia di direktori `src/Templates/default/`.

### Menggunakan Template Kustom

[](#menggunakan-template-kustom)

```
// Inisialisasi mailer dengan template kustom
$email = new \Ay4t\Emailhtml\Mailer('account_welcome');

// Tambahkan data untuk template
$email->mergeData([
    'fullname'      => 'John Doe',
    'dashboard_url' => 'https://example.com/dashboard',
    'username'      => 'johndoe',
    'password'      => '123456',
]);

// Lanjutkan dengan pengaturan lainnya seperti pada contoh dasar
$email->setSubject('Selamat Datang di Aplikasi Kami');
$email->sendTo('recipient@example.com', 'Recipient Name');
$email->send();
```

Mengirim Email dengan Attachment
--------------------------------

[](#mengirim-email-dengan-attachment)

Library ini mendukung pengiriman email dengan attachment. Terdapat dua jenis attachment yang didukung: file attachment dan string attachment.

### File Attachment

[](#file-attachment)

File attachment menggunakan path file di sistem untuk melampirkan file ke email.

#### Menambahkan File Attachment Tunggal

[](#menambahkan-file-attachment-tunggal)

```
$email = new \Ay4t\Emailhtml\Mailer();

// Tambahkan attachment tunggal
$email->addAttachment([
    'name' => 'Surat Penawaran.pdf',
    'content' => '/path/to/surat-penawaran.pdf'
]);

// Lanjutkan dengan pengaturan email lainnya
$email->setSubject('Penawaran Produk');
$email->sendTo('client@example.com', 'Client Name');
$email->send();
```

#### Menambahkan Multiple File Attachment

[](#menambahkan-multiple-file-attachment)

```
$email = new \Ay4t\Emailhtml\Mailer();

// Tambahkan multiple attachment sekaligus
$email->addMultiAttachments([
    [
        'name' => 'Surat Penawaran.pdf',
        'content' => '/path/to/surat-penawaran.pdf'
    ],
    [
        'name' => 'Invoice.pdf',
        'content' => '/path/to/invoice.pdf'
    ]
]);

// Atau tambahkan attachment satu per satu
$email->addAttachment([
    'name' => 'Katalog Produk.pdf',
    'content' => '/path/to/katalog.pdf'
]);

// Lanjutkan dengan pengaturan email lainnya
$email->setSubject('Penawaran dan Invoice');
$email->sendTo('client@example.com', 'Client Name');
$email->send();
```

### String Attachment

[](#string-attachment)

String attachment memungkinkan Anda melampirkan data langsung (string atau binary) ke email tanpa perlu file fisik. Ini sangat berguna untuk melampirkan data dari database atau konten yang dihasilkan secara dinamis.

#### Menambahkan String Attachment Tunggal

[](#menambahkan-string-attachment-tunggal)

```
$email = new \Ay4t\Emailhtml\Mailer();

// Contoh data string (misalnya dari database atau hasil generate PDF)
$pdfContent = generatePdfContent(); // Fungsi contoh yang menghasilkan konten PDF

// Tambahkan string attachment
$email->addStringAttachment(
    $pdfContent,
    'laporan-bulanan.pdf',
    null, // encoding (default: base64)
    'application/pdf', // MIME type
    'attachment' // disposition
);

// Lanjutkan dengan pengaturan email lainnya
$email->setSubject('Laporan Bulanan');
$email->sendTo('manager@example.com', 'Manager Name');
$email->send();
```

#### Menambahkan Multiple String Attachment

[](#menambahkan-multiple-string-attachment)

```
$email = new \Ay4t\Emailhtml\Mailer();

// Contoh data untuk multiple attachment
$pdfContent = generatePdfContent();
$excelContent = generateExcelContent();

// Tambahkan multiple string attachment sekaligus
$email->addMultiStringAttachments([
    [
        'string' => $pdfContent,
        'filename' => 'laporan-bulanan.pdf',
        'type' => 'application/pdf'
    ],
    [
        'string' => $excelContent,
        'filename' => 'data-penjualan.xlsx',
        'type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
    ]
]);

// Lanjutkan dengan pengaturan email lainnya
$email->setSubject('Laporan dan Data Penjualan');
$email->sendTo('manager@example.com', 'Manager Name');
$email->send();
```

API Referensi
-------------

[](#api-referensi)

### Kelas Mailer

[](#kelas-mailer)

#### Konstruktor

[](#konstruktor)

```
__construct($filename = 'account_welcome', $config = null)
```

- `$filename`: Nama file template (tanpa ekstensi .html)
- `$config`: Objek konfigurasi kustom (opsional)

#### Metode

[](#metode)

MetodeDeskripsi`mergeData(array $var)`Menggabungkan data untuk template`render($shared = false)`Render template HTML`sendTo(string $to_email, string $to_name)`Menambahkan penerima email`addCCto(string $cc_email, string $cc_name)`Menambahkan penerima CC`setSubject(string $sendSubject)`Mengatur subjek email`setAltBody(string $altBody)`Mengatur teks alternatif untuk klien email non-HTML`setDebugOutput($debugOutput)`Mengaktifkan/menonaktifkan output debug`addAttachment(array $attachment)`Menambahkan file attachment tunggal`addMultiAttachments(array $attachments)`Menambahkan multiple file attachment`addStringAttachment($string, $filename, $encoding, $type, $disposition)`Menambahkan string attachment (data langsung)`addMultiStringAttachments(array $attachments)`Menambahkan multiple string attachment`send()`Mengirim emailKontribusi
----------

[](#kontribusi)

Kontribusi untuk pengembangan library ini sangat diterima. Silakan fork repositori ini, buat perubahan, dan kirimkan pull request.

Lisensi
-------

[](#lisensi)

Library ini dilisensikan di bawah [MIT License](LICENSE).

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance38

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity46

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

Unknown

Total

1

Last Release

1280d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/831d350ec997ddc3e9d8958a40ec26668688d9120b9a4be362b5f5aa822e264f?d=identicon)[ay4t](/maintainers/ay4t)

---

Top Contributors

[![ay4t](https://avatars.githubusercontent.com/u/87152520?v=4)](https://github.com/ay4t "ay4t (17 commits)")

### Embed Badge

![Health badge](/badges/ay4t-php-mailer-template/health.svg)

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

###  Alternatives

[mgilet/notification-bundle

A simple Symfony 3 bundle for user notifications

111142.0k](/packages/mgilet-notification-bundle)[mailcarrier/mailcarrier

Mailing platform with templates and logs included

1632.0k](/packages/mailcarrier-mailcarrier)[markguinn/silverstripe-email-helpers

Silverstripe extension containing SMTP mailer class and some other classes for HTML emails

3145.4k1](/packages/markguinn-silverstripe-email-helpers)[ras/flash-alert-bundle

FlashAlertBundle provides a simplified way to handle (add/display) Symfony flash messages. Client side scripts are written in pure JavaScript.

2423.3k](/packages/ras-flash-alert-bundle)[azine/mailgunwebhooks-bundle

Symfony2 Bundle to easily capture feedback from mailgun.com via their provided webhooks

104.1k](/packages/azine-mailgunwebhooks-bundle)

PHPackages © 2026

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