PHP code example of ravisystems / ravimail-php

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

    

ravisystems / ravimail-php example snippets


use Ravimail\Client;

$rm = new Client('rvm_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');

// Send a transactional email
$resp = $rm->transactional->send([
    'to'      => '[email protected]',
    'from'    => '[email protected]',
    'subject' => 'Welcome to the show',
    'html'    => '<h1>Glad you’re here</h1>',
]);

echo $resp['data']['message_id']; // msg_xxxxxxxxxxxx

$test = new Client('rvm_test_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
$test->transactional->send([/* ... */]); // returns msg_sandbox_xxx, doesn't bill

$rm->transactional->send($payload, idempotencyKey: 'order-1024-confirmation');

use Ravimail\Resources\Webhooks;

$ok = Webhooks::verifySignature(
    $_SERVER['HTTP_X_RAVIMAIL_SIGNATURE'],
    file_get_contents('php://input'),
    'whsec_your_endpoint_secret'
);
if (!$ok) { http_response_code(401); exit; }

use Ravimail\Exception\{
    ApiException, AuthenticationException, ValidationException, RateLimitException
};

try {
    $rm->transactional->send([/* ... */]);
} catch (ValidationException $e) {
    // 422 — bad payload; $e->getMessage() has the field-level detail
} catch (RateLimitException $e) {
    // 429 — back off and retry
} catch (AuthenticationException $e) {
    // 401 — token invalid, revoked, or wrong environment
} catch (ApiException $e) {
    // any other 4xx/5xx
}

$rm = new Client(
    token: 'rvm_live_...',
    baseUrl: 'https://api.ravimail.com.br',  // override for staging if you have one
    timeout: 30,                              // seconds
);
bash
composer