PHP code example of kodhe / email

1. Go to this page and download the library: Download kodhe/email library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

kodhe / email example snippets




declare(strict_types=1);

;

$email = new Email();

$email->from('[email protected]', 'Admin')
      ->to('[email protected]')
      ->subject('Halo')
      ->message('Ini body email.')
      ->send();

$email = new Email([
    'protocol'  => 'smtp',            // mail | sendmail | smtp
    'smtp_host' => 'smtp.example.com',
    'smtp_port' => 587,
    'smtp_user' => '[email protected]',
    'smtp_pass' => 'password',
    'SMTPAuth'  => true,
    'mailtype'  => 'html',            // text | html
    'charset'   => 'UTF-8',
    'wordwrap'  => true,
    'wrapchars' => 76,
    'priority'  => 3,                 // 1 (paling tinggi) s.d. 6
]);

$email = new Email(['protocol' => 'mail', 'mailtype' => 'html']);

$email->from('[email protected]')
      ->to(['[email protected]', '[email protected]'])
      ->subject('Laporan Mingguan')
      ->message('<h1>Laporan</h1><p>Terlampir PDF.</p>')
      ->attach('/path/to/laporan.pdf')
      ->send();

// Jangan panggil send(); cukup lihat output header/body:
echo $email->printDebugger();

use Kodhe\Framework\Email\Email;

src/
├── Email.php                     # Kelas utama (API kompatibel CI3)
├── Contracts/                    # EmailInterface, TransportInterface
├── Transports/                   # MailTransport, SendmailTransport, SmtpTransport
├── Message/                      # EmailMessage, Attachment, HeaderCollection
├── Traits/                       # ConfigurableTrait, DebugTrait
├── language/email_lang.php
└── helpers/email.php             # valid_email(), send_email()