веб-сервисы Amazon — как реализовать заголовок List-Unsubscribe в электронных письмах, отправляемых AWS SES с помощью PHP SDK

Я пытался добавить пользовательский заголовок, используя AWS PHP SDK, чтобы я мог реализовать заголовок «List-unsubscribe».
Проблема в том, что я нигде не могу найти, как это реализовать.

Я прочитал документацию, но ничего.
http://docs.aws.amazon.com/aws-sdk-php/v2/api/class-Aws.Ses.SesClient.html#_sendEmail

Что я делаю неправильно?
Заранее спасибо за любую помощь.

require_once("./AWS/aws-sdk/aws-autoloader.php");

$config = array('credentials' => array('key' => $awsKey,
'secret' => $awsSecret),
'version' => 'latest',
'region' => 'us-east-1');

$client = \Aws\Ses\SesClient::factory($config);

$to = 'test@example.com';
$from = 'testfrom@example.com';
$subject = 'This is a test';
$text= 'This is a test';
$html= 'This is a <b>test</b>';
$replyTo = 'replyto@example.com';

$message=array(
// Source is required
'Source' => $from,

// Destination is required
'Destination' => array('ToAddresses' => array($to)),

// Message is required
'Message' => array(
// Subject is required
'Subject' => array(
// Data is required
'Data' => $subject,
'Charset' => 'UTF-8',
),
// Body is required
'Body' => array(
'Text' => array(
// Data is required
'Data' => $text,
'Charset' => 'UTF-8',
),
'Html' => array(
// Data is required
'Data' => $html,
'Charset' => 'UTF-8',
),
),
),

// reply To..
'ReplyToAddresses' => array($replyTo),

// Is this correct??
'AddHeaderAction' => array('header_name'=> "List-Unsubscribe",
'header_value'=> urlencode('<unsubscribeme@example.com>')));

try
{
$result = $client->sendEmail($message);
$messageID=$result->get('MessageId');
}
catch (Exception $response)
{
die('error');
}

echo 'message sent: '. $messageID;

1

Решение

Попробуйте этот код, он работает со мной, я не думаю, что вы можете использовать SendEmail Функция для реализации этого.

public static function _sendMail($to, $subject, $body, $from)
{
$random_hash = 'site_' . md5(date('r', time()));
$emailtext = "Return-Path: <{$from}>" . "\r\n";
$emailtext .= "Reply-To: <$from>" . "\r\n";
$emailtext .= "From: YOUR NAME <{$from}>" . "\r\n";
$emailtext .= 'To: ' . $to . "\r\n";
$emailtext .= "Subject: {$subject}" . "\r\n";
$emailtext .= "List-Unsubscribe: <mailto:youremail@gmail.com>". "\r\n";
$emailtext .= 'Date: ' . date('D, j M Y H:i:s O') ."\r\n";
$emailtext .= 'Message-ID: <njnjknjkr, time())),0,5) . -' . substr(md5(date('r', time())),0,5) .'-' . substr(md5(date('r', time())),0,5) . '@site.com>' ."\r\n";
$emailtext .= "Content-Type: multipart/alternative; " . "\r\n";
$emailtext .= "\t" . 'boundary="' . $random_hash . '"' . "\r\n";
$emailtext .= 'MIME-Version: 1.0' ."\r\n\r\n";
$emailtext .= '--' . $random_hash . "\r\n";
$emailtext .= 'Content-Type: text/plain; charset=us-ascii' . "\r\n";
$emailtext .= 'Content-Transfer-Encoding: 7bit' . "\r\n\r\n\r\n";
$emailtext .= '--' . $random_hash . "\r\n";
$emailtext .= 'Content-Type: text/html; charset=UTF-8' . "\r\n";
$emailtext .= 'Content-Transfer-Encoding: quoted-printable' . "\r\n\r\n\r\n";
$html = preg_replace("#(?<!\r)\n#si", "\r\n", $body) . "\r\n";
$emailtext .= quoted_printable_encode($html);
$emailtext .= '--' . $random_hash . "--";

$args = array(
'Source' => $from,
'Destinations' => array($to),
'RawMessage' => array(
'Data' => base64_encode($emailtext),
),
'FromArn' => $from,
'SourceArn' => $from,
'ReturnPathArn' => $from,
);

$client = SesClient::factory(array(
'key' => self::$__accessKey,
'secret' => self::$__secretKey,
'region' => Region::US_EAST_1
));

try {
return $client->sendRawEmail($args);
}catch (MessageRejectedException $mrEx){
return $mrEx->getMessage();
}catch (\Exception $ex){
return $ex->getMessage();
}}
1

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector