PHP code example of originphp / email

1. Go to this page and download the library: Download originphp/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/ */

    

originphp / email example snippets


Email::config('default',[
    'host' => 'smtp.example.com',
    'port' => 465,
    'username' => '[email protected]',
    'password' => 'secret',
    'timeout' => 5,
    'ssl' => true,
    'tls' => false
]);

$config = [
    'host' => 'smtp.example.com',
    'port' => 25,
    'username' => '[email protected]',
    'password' => 'secret',
    'timeout' => 5,
    'ssl' => true,
    'tls' => false
]
$email = new Email($config);

[
    'from' => ['[email protected]' => 'James'],
    'replyTo' => '[email protected]'
    'bcc' => ['[email protected]' => 'Someone','[email protected]']
]

use Origin\Email\Email;
$Email = new Email();
$Email->to('[email protected]')
    ->from('[email protected]')
    ->subject('This is a test')
    ->textMessage('This is the text content')
    ->send();

use Origin\Email\Email;
$Email = new Email();
$Email->to('[email protected]')
    ->from('[email protected]')
    ->subject('This is a test')
    ->textMessage('This is the text content')
    ->htmlMessage('<p>This is the html content</p>')
    ->format('both')
    ->send();

use Origin\Email\Email;
$Email = new Email());
$Email->to('[email protected]')
    ->from('[email protected]')
    ->subject('This is a test')
    ->htmlMessage('<p>This is the html content</p>')
    ->format('html')
    ->send();

use Origin\Email\Email;
$Email = new Email();
$Email->to('[email protected]')
    ->from('[email protected]')
    ->subject('This is a test')
    ->textMessage('This is the text content')
    ->addAttachment($filename1)
    ->addAttachment($filename2,'Logo.png')
    ->send();

use Origin\Email\Email;
$Email = new Email('gmail');

use Origin\Email\Email;
$Email = new Email();
$Email->to('[email protected]')
    ->from('[email protected]')
    ->subject('This is a test')
    ->textMessage('This is the text content')
    ->account('gmail')
    ->send();

 Email::config('gsuite', [
    'host' => 'smtp.gmail.com',
    'port' => 587,
    'username' => '[email protected]',
    'token' => 'b1816172fd2ba98f3af520ef572e3a47', // see token generation below
    'ssl' => false,
    'tls' => true
]);