HEX
Server: nginx/1.18.0
System: Linux test-ipsremont 5.4.0-214-generic #234-Ubuntu SMP Fri Mar 14 23:50:27 UTC 2025 x86_64
User: ips (1000)
PHP: 8.0.30
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/quadcode/vendor/sendgrid/sendgrid/examples/dataresidency/setregion.php
<?php
// index.php
require_once __DIR__ . '/../../sendgrid-php.php';

use SendGrid\Mail\Mail;
use SendGrid\Mail\Personalization;
use SendGrid\Mail\To;
$exceptionMessage = 'Caught exception: ';

////////////////////////////////////////////////////
// Set data residency to navigate to a region/edge. #
// sending to global data residency

$email = buildHelloEmail();
$sendgrid = buildSendgridObject("global");

try {
    $response = $sendgrid->client->mail()->send()->post($email);
    print $response->statusCode() . "\n";
    print_r($response->headers());
    print $response->body() . "\n";
} catch (Exception $e) {
    echo $exceptionMessage,  $e->getMessage(), "\n";
}

////////////////////////////////////////////////////
// sending to EU data residency

$sendgrid_eu = buildSendgridObject("eu");

try {
    $response = $sendgrid_eu->client->mail()->send()->post($email);
    print $response->statusCode() . "\n";
    print_r($response->headers());
    print $response->body() . "\n";
} catch (Exception $e) {
    echo $exceptionMessage,  $e->getMessage(), "\n";
}

////////////////////////////////////////////////////
// not configuring any region defaults to global
$sendgrid_default = new \SendGrid(getenv('SENDGRID_API_KEY'));
try {
    $response = $sendgrid_default->client->mail()->send()->post($email);
    print $response->statusCode() . "\n";
    print_r($response->headers());
    print $response->body() . "\n";
} catch (Exception $e) {
    echo $exceptionMessage,  $e->getMessage(), "\n";
}

function buildHelloEmail(): Mail
{
    $email = new Mail();
    $email->setFrom("test@example.com", "test");
    $email->setSubject("Sending with Twilio SendGrid is Fun");
    $email->addTo("test@example.co", "test");
    $email->addContent("text/plain", "and easy to do anywhere, even with PHP");
    $email->addContent(
        "text/html", "<strong>and easy to do anywhere, even with PHP</strong>"
    );
    $objPersonalization = new Personalization();

    $objTo = new To('foo@bar.com', 'foo bar');
    $objPersonalization->addTo($objTo);
    $email->addPersonalization($objPersonalization);
    return $email;
}

function buildSendgridObject($region): SendGrid
{
    $sendgrid = new \SendGrid(getenv('SENDGRID_API_KEY'));
    $sendgrid->setDataResidency($region);
    return $sendgrid;
}