Sending Raw via api

0

We need to be able to personalise headers which seems to mean we need to send a raw sender - is there a guide on how to do this in AWS - ideally using PHP?

asked a year ago212 views
1 Answer
0
use Aws\Ses\SesClient;

$client = SesClient::factory(array(
    'version' => 'latest',
    'region' => 'us-west-2', // replace with your desired region
    'credentials' => array(
        'key' => 'YOUR_AWS_ACCESS_KEY_ID',
        'secret' => 'YOUR_AWS_SECRET_ACCESS_KEY',
    ),
));

// Set the raw message content
$rawMessage = "From: sender@example.com\r\n";
$rawMessage .= "To: recipient@example.com\r\n";
$rawMessage .= "Subject: Test email\r\n";
$rawMessage .= "Content-Type: text/html; charset=us-ascii\r\n\r\n";
$rawMessage .= "<h1>This is a test email</h1>";

$result = $client->sendRawEmail(array(
    'RawMessage' => array(
        'Data' => base64_encode($rawMessage),
    ),
));

// Check for errors
if (!$result['MessageId']) {
    echo "Error sending email: " . $result['Error']['Message'];
} else {
    echo "Email sent successfully";
}

profile picture
EXPERT
answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions