PHP code example of sharpapi / laravel-content-detect-emails

1. Go to this page and download the library: Download sharpapi/laravel-content-detect-emails 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/ */

    

sharpapi / laravel-content-detect-emails example snippets




namespace App\Http\Controllers;

use GuzzleHttp\Exception\GuzzleException;
use SharpAPI\ContentDetectEmails\ContentDetectEmailsService;

class ContentController extends Controller
{
    protected ContentDetectEmailsService $emailDetectionService;

    public function __construct(ContentDetectEmailsService $emailDetectionService)
    {
        $this->emailDetectionService = $emailDetectionService;
    }

    /**
     * @throws GuzzleException
     */
    public function detectEmailAddresses(string $text)
    {
        $statusUrl = $this->emailDetectionService->detectEmails($text);
        
        $result = $this->emailDetectionService->fetchResults($statusUrl);

        return response()->json($result->getResultJson());
    }
}

use GuzzleHttp\Exception\ClientException;

try {
    $statusUrl = $this->emailDetectionService->detectEmails('Contact us at [email protected] or [email protected]');
} catch (ClientException $e) {
    echo $e->getMessage();
}