PHP code example of leadm / leadmail

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

    

leadm / leadmail example snippets


Mail::to('[email protected]')->send(new WelcomeMail());

LeadMail::sendEmail([
    'from' => ['email' => '[email protected]', 'name' => 'Your App'],
    'to' => [['email' => '[email protected]', 'name' => 'User']],
    'subject' => 'Welcome!',
    'html_body' => '<h1>Welcome to our app</h1>',
]);

$result = LeadMail::verifyEmail('[email protected]');

if ($result['data']['valid']) {
    // Email is deliverable
}

public function rules(): array
{
    return [
        'email' => ['

$domains = LeadMail::getDomains();
// ['yourdomain.com', 'anotherdomain.com']

use LeadM\LeadMail\Exceptions\LeadMailRequestException;
use LeadM\LeadMail\Exceptions\LeadMailConnectionException;

try {
    LeadMail::sendEmail([...]);
} catch (LeadMailRequestException $e) {
    $e->statusCode();        // e.g. 422, 502
    $e->errorCode();         // e.g. "TRANSPORT_ERROR" (from the API envelope)
    $e->logId();             // the email log id, when available
    $e->validationErrors();  // ['from.email' => ['...']] on a 422
    $e->isValidationError();
    $e->isAuthenticationError();
} catch (LeadMailConnectionException $e) {
    // Service unreachable — safe to queue and retry yourself.
}

use LeadM\LeadMail\Events\LeadMailWebhookReceived;

Event::listen(function (LeadMailWebhookReceived $received) {
    $event = $received->event;

    if ($event->isFailure()) {
        // $event->logId, $event->errorCode, $event->errorMessage,
        // $event->from, $event->to, $event->subject, $event->metadata
    }
});
bash
php artisan leadmail:install
bash
php artisan leadmail:install