Amazon SES RawMessage:缺少必需的标头“发件人" [英] Amazon SES RawMessage: Missing required header 'From'

查看:110
本文介绍了Amazon SES RawMessage:缺少必需的标头“发件人"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


use PHPMailer\PHPMailer\PHPMailer;
use Aws\Ses\SesClient;
use Aws\Ses\Exception\SesException;
require 'vendor/autoload.php';

if(!function_exists("sendmailalexraw")){

function sendmailalexraw($email,$subject,$messages,$definesender)
{



// Replace sender@example.com with your "From" address. 
// This address must be verified with Amazon SES.
$sender = $definesender;           
$sendername = 'Alex';

// Replace recipient@example.com with a "To" address. If your account 
// is still in the sandbox, this address must be verified.
$recipient = $email;    

// Specify a configuration set.
$configset = 'ConfigSet';

// Replace us-west-2 with the AWS Region you're using for Amazon SES.
$region = 'eu-west-1'; 

$subject = $subject;

$htmlbody = <<<EOD
<html>
<head></head>
<body>
<h1>Hello!</h1>
<p>Please see the attached file for a list of customers to contact.</p>
</body>
</html>
EOD;

$textbody = <<<EOD
Hello,
Please see the attached file for a list of customers to contact.
EOD;

//// The full path to the file that will be attached to the email. 
$att = 'path/to/customers-to-contact.xlsx';

// Create an SesClient.
$client = SesClient::factory(array(
    'version'=> 'latest',     
    'region' => $region
));

// Create a new PHPMailer object.
$mail = new PHPMailer;

// Add components to the email.
$mail->setFrom($sender, $sendername);
$mail->addAddress($recipient);
$mail->Subject = $subject;
$mail->Body = $htmlbody;
$mail->AltBody = $textbody;
$mail->addAttachment($att);
$mail->addCustomHeader('X-SES-CONFIGURATION-SET', $configset);

// Attempt to assemble the above components into a MIME message.
if (!$mail->preSend()) {
    echo $mail->ErrorInfo;
} else {
    // Create a new variable that contains the MIME message.
    $message = $mail->getSentMIMEMessage();
}

// Try to send the message.
try {
    $result = $client->sendRawEmail([
        'RawMessage' => [
            'Data' => $messages
        ]
    ]);
    // If the message was sent, show the message ID.
    $messageId = $result->get('MessageId');
    echo("Email sent! Message ID: $messageId"."\n");
} catch (SesException $error) {
    // If the message was not sent, show a message explaining what went wrong.
    echo("The email was not sent. Error message: "
         .$error->getAwsErrorMessage()."\n");
}

}
}



$email='example@gmail.com';
$subject='abc';
$messages='xyz';
$definesender='info@verifieddomain.net';
sendmailalexraw($email,$subject,$messages,$definesender);


?>


我正在尝试通过Amazon SES发送RawMessage,但是我得到了:

I am trying to send RawMessage with Amazon SES but I get :

电子邮件未发送.错误消息:缺少必需的标题发件人".

我使用的发件人已经过验证,我的Amazon SES已激活(不在sendbox中).

Sender I use it's verified, my Amazon SES it's active (out of sendbox ) .

我需要作为RAW消息发送,以为要发送的电子邮件创建退订选项.正如我从文档中读到的那样,它必须是原始电子邮件才能添加此参数.谢谢!

I am needing to send as RAW Message to create unsubscribe option for emails I am sening. As I read from documentation it have to be raw email to be able to add this parameters.Thank you !

推荐答案

您必须对消息进行base64编码:

You have to base64 encode the message :

$result = $client->sendRawEmail([
    'RawMessage' => [
        'Data' => base64_encode($messages)
    ]
]);

这篇关于Amazon SES RawMessage:缺少必需的标头“发件人"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆