1. Go to this page and download the library: Download rlnks/php-mail-audit 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/ */
// From a string
$result = $audit->analyze('<div style="display:flex;">Hello</div>');
// From a file
$result = $audit->analyze(file_get_contents('emails/welcome.html'));
// From a rendered template (e.g. Twig)
$html = $twig->render('emails/welcome.html.twig', $data);
$result = $audit->analyze($html);
// Reconstruct the matched snippet from offset
$snippet = substr($html, $loc['offset_start'], $loc['offset_end'] - $loc['offset_start']);
// new MailAudit([], ['en', 'fr'])
'message' => [
'en' => 'Flexbox is not supported in Outlook desktop...',
'fr' => 'Flexbox n\'est pas supporté dans Outlook desktop...',
]
[
'id' => 'no-flexbox',
'severity' => 'error', // severity the rule would have had if triggered
'message' => 'No flexbox layout detected — good compatibility with Outlook desktop.',
'tags' => ['css', 'layout'],
]
[
'total_rules_checked' => 56, // total rules evaluated
'total_issues' => 3, // rules that fired
'errors' => 1, // severity = error
'warnings' => 1, // severity = warning
'infos' => 1, // severity = info
'passed' => 9, // rules that passed with a success message
]
$audit = new MailAudit(locale: 'fr'); // or 'es', 'de', 'pt'
$result = $audit->analyze($html);
// $result['insights'][0]['message'] → string in French
// $result['insights'][0]['fix'] → string in French
$audit = new MailAudit([
'auto_update' => true,
'ttl_days' => 7, // re-fetch after 7 days
'endpoint' => 'https://kb.mailaudit.io/rules.json',
'api_key' => getenv('MAILAUDIT_API_KEY'), // optional, pro tier
'cache_path' => __DIR__ . '/var/mailaudit-rules.json', // must be writable
]);
use MailAudit\Loader\RuleLoader;
use MailAudit\Analysis\RuleEngine;
use MailAudit\Analysis\ScoringEngine;
use MailAudit\Feedback\FeedbackGenerator;
$bundled = (new RuleLoader())->load();
$custom = [json_decode(file_get_contents('rules/no-video.json'), true)];
$rules = array_merge($bundled, $custom);
$triggered = (new RuleEngine($rules))->analyze($html);
$score = (new ScoringEngine())->calculate($triggered);
$insights = (new FeedbackGenerator('en'))->generate($triggered);
use MailAudit\Detection\DetectorInterface;
class MjmlTagDetector implements DetectorInterface
{
public function matches(string $html, array $detection): bool
{
foreach ($detection['tags'] ?? [] as $tag) {
if (str_contains($html, "<mj-{$tag}")) {
return true;
}
}
return false;
}
}
use MailAudit\Detection\DetectorFactory;
DetectorFactory::register('mjml_tag', MjmlTagDetector::class);
use MailAudit\MailAudit;
$result = (new MailAudit())->analyze(file_get_contents('email.html'));
if ($result['score'] < 80) {
foreach ($result['insights'] as $insight) {
if ($insight['severity'] === 'error') {
throw new RuntimeException("Email has blocking issues: {$insight['message']}");
}
}
}
// config/services.yaml
services:
MailAudit\MailAudit:
arguments:
$config:
auto_update: true
ttl_days: 7
endpoint: '%env(MAILAUDIT_ENDPOINT)%'
api_key: '%env(MAILAUDIT_API_KEY)%'
cache_path: '%kernel.cache_dir%/mailaudit-rules.json'
// In a service or controller
public function __construct(private MailAudit $audit) {}
public function preview(string $html): array
{
return $this->audit->analyze($html);
}
json
{
"message": {
"en": "Flexbox is not supported in Outlook.",
"fr": "Flexbox n'est pas supporté dans Outlook.",
"de": "Flexbox wird in Outlook nicht unterstützt."
},
"fix": {
"en": "Use HTML tables for layout.",
"fr": "Utilisez des tables HTML pour la mise en page.",
"de": "Verwenden Sie HTML-Tabellen für das Layout."
}
}
json
{
"id": "no-video",
"version": "1.0",
"updated_at": "2026-05-09",
"source": "https://www.caniemail.com/features/html-video/",
"tier": "free",
"severity": "error",
"weight": 12,
"tags": ["html", "media"],
"detection": {
"type": "html_tag",
"patterns": ["video"]
},
"affected_clients": {
"outlook_desktop": { "supported": false, "versions": "all" },
"gmail_web": { "supported": false }
},
"message": {
"en": "<video> elements are not supported in Outlook or Gmail.",
"fr": "Les éléments <video> ne sont pas supportés dans Outlook ni Gmail."
},
"fix": {
"en": "Use a linked image (GIF or static) as a fallback for video content.",
"fr": "Utiliser une image liée (GIF ou statique) comme fallback pour le contenu vidéo."
}
}