gpt4 book ai didi

php - AWS : ses with attach files

转载 作者:行者123 更新时间:2023-12-01 16:26:51 24 4
gpt4 key购买 nike

我将 Laravel 4 框架与 AWS sdk 用于 SES。我可以使用 sendEmail 函数发送常规电子邮件。我希望能够将文件附加到电子邮件中,问题是我找不到如何执行此操作。

是否可以使用 sendEmail 函数附加文件,或者我必须使用 send_raw_email 函数? (如何做到这一点?)

这是我使用 SES 的方式:

$msg['Source'] = Config::get('mail.mailSource');
$msg['Destination']['ToAddresses'][] = $_GET['email'];
$msg['Message']['Subject']['Data'] = "bla bla";
$msg['Message']['Body']['Text']['Data'] = 'bla bla';
$msg['Message']['Body']['Html']['Data'] = 'bla bla';

$ses = AWS::get('ses');
$ses->sendEmail($msg);

我在 laravel 中查看了 AWS sdk,发现有一个数组包含 sendEmail 函数的要求,但没有附加文件的线索

'SendEmail' => array(
'httpMethod' => 'POST',
'uri' => '/',
'class' => 'Aws\\Common\\Command\\QueryCommand',
'responseClass' => 'SendEmailResponse',
'responseType' => 'model',
'parameters' => array(
'Action' => array(
'static' => true,
'location' => 'aws.query',
'default' => 'SendEmail',
),
'Version' => array(......

最佳答案

我发现发送带有附件的电子邮件(使用 SES 服务)的唯一方法是使用 SendRawEmail 方法。

  $message = "To: ". $_GET['email'] ."\n";
$message .= "From: ". $msg['Source'] ."\n";
$message .= "Subject: Example SES mail (raw)\n";
$message .= "MIME-Version: 1.0\n";
$message .= 'Content-Type: multipart/mixed; boundary="aRandomString_with_signs_or_9879497q8w7r8number"';
$message .= "\n\n";
$message .= "--aRandomString_with_signs_or_9879497q8w7r8number\n";
$message .= 'Content-Type: text/plain; charset="utf-8"';
$message .= "\n";
$message .= "Content-Transfer-Encoding: 7bit\n";
$message .= "Content-Disposition: inline\n";
$message .= "\n";
$message .= "Dear new tester,\n\n";
$message .= "Attached is the file you requested.\n";
$message .= "\n\n";
$message .= "--aRandomString_with_signs_or_9879497q8w7r8number\n";
$message .= "Content-ID: \<77987_SOME_WEIRD_TOKEN_BUT_UNIQUE_SO_SOMETIMES_A_@domain.com_IS_ADDED\>\n";
$message .= 'Content-Type: application/zip; name="shell.zip"';
$message .= "\n";
$message .= "Content-Transfer-Encoding: base64\n";
$message .= 'Content-Disposition: attachment; filename="file.png"';
$message .= "\n";
$message .= base64_encode( $attachedFile );
$message .= "\n";
$message .= "--aRandomString_with_signs_or_9879497q8w7r8number--\n";

$sendMsg['RawMessage']['Data'] = (string)base64_encode($message);
$sendMsg['RawMessage']['Source'] = $msg['Source'];
$sendMsg['RawMessage']['Destinations'] = $_GET['email'];

$ses->SendRawEmail($sendMsg);

注意这一行:

$message .= '内容处置:附件; filename="file.png"';

$message .= base64_encode( $attachedFile );

关于php - AWS : ses with attach files,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23829198/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com