Php 附加亚马逊SES服务的自定义电子邮件标题

Php 附加亚马逊SES服务的自定义电子邮件标题,php,email-headers,amazon-ses,Php,Email Headers,Amazon Ses,我正在使用Amazon SES发送电子邮件,我想在发送给用户之前附加一个自定义标题,因为我正在制作一个代理电子邮件系统,用于回复我网站上的线程,因此保留ID以跟踪在电子邮件中发布到哪个线程 我看不出如何从AmazonSES的文档中附加自定义头,除了解释他们接受哪些头,但没有说明如何绑定它,我使用的是针对PHP的 我希望能够在名为X-Thread-ID的头中插入一个数字,我将如何继续 编辑:对于Jack的回答,我无法正确发送电子邮件,它不断给我以下错误: CFSimpleXML Object (

我正在使用Amazon SES发送电子邮件,我想在发送给用户之前附加一个自定义标题,因为我正在制作一个代理电子邮件系统,用于回复我网站上的线程,因此保留ID以跟踪在电子邮件中发布到哪个线程

我看不出如何从AmazonSES的文档中附加自定义头,除了解释他们接受哪些头,但没有说明如何绑定它,我使用的是针对PHP的

我希望能够在名为
X-Thread-ID
的头中插入一个数字,我将如何继续


编辑:对于Jack的回答,我无法正确发送电子邮件,它不断给我以下错误:

CFSimpleXML Object
(
    [Type] => Sender
    [Code] => InvalidParameterValue
    [Message] => Missing final '@domain'
)
我的标题与此一模一样

To: myemail@hotmail.co.uk <YES>
From: developer@mysite.com <MySite>
X-Thread-ID: 429038
至:myemail@hotmail.co.uk 
发件人:developer@mysite.com 
X-Thread-ID:429038

我不确定您对当前的包装器有多感兴趣,但我只使用Amazon SDK for PHP附带的包装器,它可以从Amazon本身下载

$ses = new AmazonSES(AWS_ACCESS_KEY, AWS_ACCESS_SECRET);

$headers = join("\r\n", array(
    "To: $recipient",
    "X-Thread-ID: 123test",
));
$body = "<html><body> ... </body></html>";

$res = $ses->send_raw_email(array(
    'Data' => chunk_split(base64_encode("$headers\r\n\r\n$body"))
), array());

// check API result
if (!$res->isOK()) {
    throw new Exception(print_r($res->body->Error, true));
}
// inspect message id
$messageId = (string)$res->body->SendRawEmailResult->MessageId
$ses=新亚马逊(AWS\u访问密钥,AWS\u访问密钥);
$headers=join(“\r\n”,数组(
“收件人:$recipient”,
“X-Thread-ID:123test”,
));
$body=“…”;
$res=$ses->发送原始电子邮件(数组)(
'Data'=>chunk\u split(base64\u编码(“$headers\r\n\r\n$body”))
),数组());
//检查API结果
如果(!$res->isOK()){
抛出新异常(print_r($res->body->Error,true));
}
//检查消息id
$messageId=(字符串)$res->body->sendrawmailresult->messageId
编辑

此电子邮件标题:

To: myemail@hotmail.co.uk <YES>
至:myemail@hotmail.co.uk 
应(反转):

收件人:是

双引号应该用于带有空格的名称。

快进到2017年,答案是(根据亚马逊的说法):

(参考号:)


+1用于官方SDK。快速、简单、直接从亚马逊获得。@杰克,我有一个关于我遇到的错误的问题。哦!对不起,我忘了说我已经编辑了我的帖子-你可以从那里阅读,对不起@烧掉密码点火器这是一个容易犯的错误,更新的答案:)@Jack-Aha,我的错。谢谢你:-)
To: YES <myemail@hotmail.co.uk>
<?php

// Modify the path in the require statement below to refer to the 
// location of your Composer autoload.php file.
require 'path_to_sdk_inclusion';

// Instantiate a new PHPMailer 
$mail = new PHPMailer;

// Tell PHPMailer to use SMTP
$mail->isSMTP();

// Replace sender@example.com with your "From" address. 
// This address must be verified with Amazon SES.
$mail->setFrom('sender@example.com', 'Sender Name');

// Replace recipient@example.com with a "To" address. If your account 
// is still in the sandbox, this address must be verified.
// Also note that you can include several addAddress() lines to send
// email to multiple recipients.
$mail->addAddress('recipient@example.com', 'Recipient Name');

// Replace smtp_username with your Amazon SES SMTP user name.
$mail->Username = 'smtp_username';

// Replace smtp_password with your Amazon SES SMTP password.
$mail->Password = 'smtp_password';

// Specify a configuration set. If you do not want to use a configuration
// set, comment or remove the next line.
$mail->addCustomHeader('X-SES-CONFIGURATION-SET', 'ConfigSet');

// If you're using Amazon SES in a region other than US West (Oregon), 
// replace email-smtp.us-west-2.amazonaws.com with the Amazon SES SMTP  
// endpoint in the appropriate region.
$mail->Host = 'email-smtp.us-west-2.amazonaws.com';

// The port you will connect to on the Amazon SES SMTP endpoint.
$mail->Port = 465;

// The subject line of the email
$mail->Subject = 'Amazon SES test (SMTP interface accessed using PHP)';

// The HTML-formatted body of the email
$mail->Body = '<h1>Email Test</h1>
    <p>This email was sent through the 
    <a href="https://aws.amazon.com/ses">Amazon SES</a> SMTP
    interface using the <a href="https://github.com/PHPMailer/PHPMailer">
    PHPMailer</a> class.</p>';

// Tells PHPMailer to use SMTP authentication
$mail->SMTPAuth = true;

// Enable SSL encryption
$mail->SMTPSecure = 'ssl';

// Tells PHPMailer to send HTML-formatted email
$mail->isHTML(true);

// The alternative email body; this is only displayed when a recipient
// opens the email in a non-HTML email client. The \r\n represents a 
// line break.
$mail->AltBody = "Email Test\r\nThis email was sent through the 
    Amazon SES SMTP interface using the PHPMailer class.";

if(!$mail->send()) {
    echo "Email not sent. " , $mail->ErrorInfo , PHP_EOL;
} else {
    echo "Email sent!" , PHP_EOL;
}
?>