How to Validate EML Email Files in PHP

Cloudmersive
1 min readApr 1, 2024

--

We can easily validate our EML files with just a few lines of PHP code.

To handle our EML file validation, we’ll simply call a free, low-code API using complementary PHP code examples.

We can install the SDK with Composer by running the below command from our command line:

composer require cloudmersive/cloudmersive_document_convert_api_client

Next, we can turn our attention to authorization. To make free API calls, we’ll just need a free Cloudmersive API key (this will allow a limit of 800 API calls per month with no additional commitments).

Finally, we can call the function to validate our EML file using the below code. If our file isn’t valid, we’ll get details about important errors and warnings in our API response:

<?php
require_once(__DIR__ . '/vendor/autoload.php');

// Configure API key authorization: Apikey
$config = Swagger\Client\Configuration::getDefaultConfiguration()->setApiKey('Apikey', 'YOUR_API_KEY');



$apiInstance = new Swagger\Client\Api\ValidateDocumentApi(


new GuzzleHttp\Client(),
$config
);
$input_file = "/path/to/inputfile"; // \SplFileObject | Input file to perform the operation on.

try {
$result = $apiInstance->validateDocumentEmlValidation($input_file);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling ValidateDocumentApi->validateDocumentEmlValidation: ', $e->getMessage(), PHP_EOL;
}
?>

That’s all there is to it — no more code required. Now we can quickly and easily validate EML files in PHP.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

No responses yet