【问题标题】:Expected / got ; error when sending SES emails with attachments预期/得到;发送带附件的 SES 电子邮件时出错
【发布时间】:2021-07-29 05:59:14
【问题描述】:

使用 PHP 发送 SES 电子邮件时,无论我使用 SMTP 终端节点还是 AWS 开发工具包,在发送带有附件的原始电子邮件时都会收到类似的错误。在AWS forumsWordpress plugin 中报告了类似的错误。当我省略附件时,电子邮件每次发送都没有问题。

通过 SMTP 我收到以下错误:

554 Transaction failed: Expected '/', got null

使用 SDK ("aws/aws-sdk-php": "^3.178") 时,我收到以下信息:

exception 'Aws\Ses\Exception\SesException' with message 'Error executing "SendRawEmail" on "https://email.eu-west-2.amazonaws.com"; AWS HTTP error: Client error: `POST https://email.eu-west-2.amazonaws.com` resulted in a `400 Bad Request` response:
 <ErrorResponse xmlns="http://ses.amazonaws.com/doc/2010-12-01/">
   <Error>
     <Type>Sender</Type>
     <Code>InvalidPara (truncated...)
  InvalidParameterValue (client): Expected '/', got ; - <ErrorResponse xmlns="http://ses.amazonaws.com/doc/2010-12-01/">
   <Error>
     <Type>Sender</Type>
     <Code>InvalidParameterValue</Code>
     <Message>Expected '/', got ;</Message>
   </Error>
   <RequestId>abc123-abc1-abc1-abc1-abc123acb123</RequestId>
 </ErrorResponse>

我正在使用 PHPMailer 发送消息:

// Prepare mime message
$mail = new PHPMailer();
$mail->setFrom($user['email'], $user['full_name']);
$mail->addAddress($recipient);
$mail->Subject = $entity['title'];
$mail->isHTML(true);
$mail->Body = $entity['body'];
$mail->addStringAttachment(
    'My DOMPDF content',
    'attachment.pdf',
    PHPMailer::ENCODING_BASE64,
    'pdf'
);
$mail->preSend();
$raw = $mail->getSentMIMEMessage();

// Prepare SES client
$ses = new SesClient([
    'version' => '',
    'region' => 'eu-west-2'
]);

// Send email
$ses->sendRawEmail([
    'RawMessage' => [
        'Data' => $raw,
    ],
]);

【问题讨论】:

    标签: phpmailer amazon-ses aws-php-sdk


    【解决方案1】:

    应该一直使用application/pdf作为内容类型而不是pdf,否则附件添加为:

     --b1_IUbTPYYE0RFpfwGdeVX4Ggi2ErEKTd6JwKwjRJzEtE
     Content-Type: pdf; name=attachmentpdf
     Content-Transfer-Encoding: base64
     Content-Disposition: attachment; filename=attachment.pdf
    

    代替:

     --b1_EPhqEYFUvxbgyaVbkH4eNDQXBxsXAJpRwTMMkcTY
     Content-Type: application/pdf; name=attachment.pdf
     Content-Transfer-Encoding: base64
     Content-Disposition: attachment; filename=attachment.pdf
    

    验证错误出现在需要正斜杠的内容类型上:doh:。

    $mail->addStringAttachment(
        'My DOMPDF content',
        'attachment.pdf',
        PHPMailer::ENCODING_BASE64,
        'application/pdf'
    );
    

    【讨论】:

      猜你喜欢
      • 2017-09-28
      • 2019-12-07
      • 2022-11-25
      • 2012-06-21
      • 1970-01-01
      • 1970-01-01
      • 2019-06-05
      • 2020-01-12
      • 1970-01-01
      相关资源
      最近更新 更多