2

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

我看不到如何从 Amazon SES 的文档中附加自定义标头,除了这个页面解释了他们接受哪些标头但没有说明如何绑定它,我正在使用这个为 PHP 制作的SES 包装器。

我希望能够注入一个以X-Thread-ID数字命名的标头,我该怎么做呢?


编辑:对于杰克的回答,我无法正确发送电子邮件,它一直给我这个错误:

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
4

2 回答 2

6

我不确定您对当前包装器的依恋程度,但我只使用 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

编辑

此电子邮件标题:

To: myemail@hotmail.co.uk <YES>

应该是(反转):

To: YES <myemail@hotmail.co.uk>

带空格的名称应使用双引号。

于 2012-09-28T04:08:10.603 回答
0

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

(参考:通过以编程方式访问 Amazon SES SMTP 接口发送电子邮件

<?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;
}
?>
于 2017-09-26T08:15:23.997 回答