PHP code example of desttools / transmail

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

    

desttools / transmail example snippets


// Direct nce './transmail/ZeptoMailClient.php';

// Or via Composer autoloading:

$msg = new \stdClass();

$msg->subject  = 'My message subject';
$msg->htmlbody = '<p>My HTML-formatted message</p>';
$msg->textbody = 'My text-only message'; // omit if sending HTML only
$msg->to       = ['[email protected]', 'Joe Customer'];
$msg->from     = ['[email protected]', 'XYZ Company'];

$client = new \ZeptoMail\ZeptoMailClient($msg);
$result = $client->send();

if ($result) {
    // success
} else {
    // failure
}

$msg = new \stdClass();

// Required
$msg->subject  = 'My message subject';
$msg->htmlbody = '<p>My HTML-formatted message</p>';
$msg->textbody = 'My text-only message';
$msg->to       = ['[email protected]', 'Joe Customer'];
$msg->from     = ['[email protected]', 'XYZ Company'];

// Optional
$msg->reply_to         = ['[email protected]', 'XYZ Company'];
$msg->cc               = ['[email protected]', 'Someone'];
$msg->bcc              = ['[email protected]', 'Somebody Else'];
$msg->track_clicks     = true;
$msg->track_opens      = true;
$msg->client_reference = null; // arbitrary string, passed through to API
$msg->mime_headers     = null; // array of additional MIME headers
$msg->attachments      = null; // array — see Attachments section
$msg->inline_images    = null; // array

// Pass API key and bounce address directly (overrides env vars)
$client = new \ZeptoMail\ZeptoMailClient($msg, 'myapikey', '[email protected]');
$result = $client->send();

$msg->to = [
    ['[email protected]', 'Alice'],
    ['[email protected]',   'Bob'],
];

$msg->to = '[email protected]';
// or
$msg->to = ['[email protected]', 'Joe Customer'];
// or — order doesn't matter, email is detected by format:
$msg->to = ['Joe Customer', '[email protected]'];

$client = new \ZeptoMail\ZeptoMailClient($msg, 'myapikey', null, true);
$result = $client->send(); // stdClass API response object

// Reference for API error codes:
// https://www.zoho.com/zeptomail/help/api/error-codes.html

$msg->mime_headers = [
    ['CustId'   => '1234',
     'CustName' => 'Bob Smith'],
];

$attachments = [];

$file     = 'filename.jpg';
$path     = '/path/to/' . $file;
$filedata = file_get_contents($path);

if ($filedata) {
    $attachments[] = [
        'content'   => base64_encode($filedata),
        'mime_type' => mime_content_type($path),
        'name'      => $file,
    ];
}

$msg->attachments = $attachments;


// or: 

$msg = new \stdClass();

$msg->subject  = 'My message subject';
$msg->textbody = 'My text-only message';
$msg->htmlbody = '<p>My HTML-formatted message</p>';
$msg->to       = ['[email protected]', 'Joe Customer'];
$msg->from     = ['[email protected]', 'XYZ Company'];

$tmail  = new \Transmail\TransmailClient($msg);
$result = $tmail->send();

$msg = new \stdClass();

$msg->subject         = 'My message subject';
$msg->textbody        = 'My text-only message';
$msg->htmlbody        = '<p>My HTML-formatted message</p>';
$msg->to              = ['[email protected]', 'Joe Customer'];
$msg->from            = ['[email protected]', 'XYZ Company'];
$msg->reply_to        = ['[email protected]', 'XYZ Company'];
$msg->cc              = ['[email protected]', 'Someone'];
$msg->bcc             = ['[email protected]', 'Somebody Else'];
$msg->track_clicks    = true;
$msg->track_opens     = true;
$msg->client_reference = null;
$msg->mime_headers    = null;
$msg->attachments     = null;
$msg->inline_images   = null;

$tmail  = new \Transmail\TransmailClient($msg, 'myapikey', '[email protected]', true);
$result = $tmail->send();