簡體   English   中英

使用AWS sdk php通過SES發送原始電子郵件

[英]Send Raw Email via SES using the AWS sdk php

我正在搜索通過AWS SES服務發送HTML格式的電子郵件。

我正在使用PHP SDK e,這是我使用的控制器的代碼:

    ....
    $to         = "dev@society.com";
    // You'll need to be able to send as this address in SES
    $from       = "marketing@society.com";

    // $html = file_get_contents("../resources/email/activation/activation.html");
    // $html = sprintf($html);
    // $html = mb_convert_encoding($html, "HTML-ENTITIES", "UTF-8");

    // our html message

    $html = <<<EOF
    <!DOCTYPE html>
    <html>
    <body>
    <h1>This text should be large, because it is formatted as a header in HTML.</h1>
    <p>Here is a formatted link: <a href="http://docs.aws.amazon.com/ses/latest/DeveloperGuide/Welcome.html">Amazon SES Developer Guide</a>.</p>
    </body>
    </html>
    EOF;

    // our attachments - these are relative to the current file
    $attachments    = array();

    $mailer         = new EmailServiceProvider();

    /** @var boolean|string $messageId Identify of the email sended or false if an expetion is thrown */
    $messageId      = $mailer->send($to, $subject, $from, $html, $attachments);
    ....

EmailService的代碼是: http ://pastebin.com/zhKDEsvp

如果我使用此代碼,則電子郵件不是HTML格式的。 這是到達的:

Subject: Registrazione servizio
MIME-Version: 1.0
Content-type: multipart/alternative; boundary="207873e15f9df22df8212df410ead01cfe1b9f7c"

--207873e15f9df22df8212df410ead01cfe1b9f7c
Content-Type: text/html; charset=iso-8859-1

<!DOCTYPE html>
<html>
<body>
<h1>This text should be large, because it is formatted as a header in HTML.</h1>
<p>Here is a formatted link: <a href="http://docs.aws.amazon.com/ses/latest/DeveloperGuide/Welcome.html">Amazon SES Developer Guide</a>.</p>
</body>
</html>

--207873e15f9df22df8212df410ead01cfe1b9f7c--

其他答案說在此處添加base_64_encode

    $args = array(
        'Source'        => $from,
        'Destinations'  => array($to),
        'RawMessage'    => array(
            'Data' => base_64_encode($rawEmail)
        )
    );

但是,如果我使用它,則不會發送電子郵件,並且會給出“傳遞狀態”:

An error occurred while trying to deliver the mail to the following recipients:
dev@society.com
Action: failed
Final-Recipient: rfc822; dev@society.com
Diagnostic-Code: smtp; 550-5.7.1 [54.240.4.25      11] Our system has detected that this message is not
 550-5.7.1 RFC 5322 compliant:
 550-5.7.1 'From' header is missing.
 550-5.7.1 To reduce the amount of spam sent to Gmail, this message has been
 550-5.7.1 blocked. Please visit
 550-5.7.1  https://support.google.com/mail/?p=RfcMessageNonCompliant
 550 5.7.1 and review RFC 5322 specifications for more information. ud19si31267939wjb.199 - gsmtp
Status: 5.7.1



---------- Messaggio inoltrato ----------
From: 
To: 
Cc: 
Date: 
Subject: 
ClN1YmplY3Q6IFJlZ2lzdHJhemlvbmUgc2Vydml6aW8gSG9wc3RvawpNSU1FLVZlcnNpb246IDEuMApDb250ZW50LXR5cGU6IG11bHRpcGFydC9hbHRlcm5hdGl2ZTsgYm91bmRhcnk9IjkzY2E3ZTcwZDk2OWNkMGU5NzEwNzBiMGQwMjllNzUwY2E1N2VjNzciCgotLTkzY2E3ZTcwZDk2OWNkMGU5NzEwNzBiMGQwMjllNzUwY2E1N2VjNzcKQ29udGVudC1UeXBlOiB0ZXh0L2h0bWw7IGNoYXJzZXQ9aXNvLTg4NTktMQoKPCFET0NUWVBFIGh0bWw+CjxodG1sPgo8Ym9keT4KPGgxPlRoaXMgdGV4dCBzaG91bGQgYmUgbGFyZ2UsIGJlY2F1c2UgaXQgaXMgZm9ybWF0dGVkIGFzIGEgaGVhZGVyIGluIEhUTUwuPC9oMT4KPHA+SGVyZSBpcyBhIGZvcm1hdHRlZCBsaW5rOiA8YSBocmVmPSJodHRwOi8vZG9jcy5hd3MuYW1hem9uLmNvbS9zZXMvbGF0ZXN0L0RldmVsb3Blckd1aWRlL1dlbGNvbWUuaHRtbCI+QW1hem9uIFNFUyBEZXZlbG9wZXIgR3VpZGU8L2E+LjwvcD4KPC9ib2R5Pgo8L2h0bWw+CgotLTkzY2E3ZTcwZDk2OWNkMGU5NzEwNzBiMGQwMjllNzUwY2E1N2VjNzctLQo=
Message-ID: <01020156d5c31991-07b878e4-bf3d-4d2c-85b2-d8ca1dcd9c9e-000000@eu-west-1.amazonses.com>
From: marketing@society.com
Date: Mon, 29 Aug 2016 10:05:48 +0000
X-SES-Outgoing: 2016.08.29-54.240.4.25
Feedback-ID: 1.eu-west-1.sSCOXf1mGsy1MFXDAp1+U0vN705joaXLM/BN/BVnYzE=:AmazonSES
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple;
        s=ihchhvubuqgjsxyuhssfvqohv7z3u4hn; d=amazonses.com; t=1472465148;
        h=Message-ID:From:Date:Feedback-ID;
        bh=frcCV1k9oG9oKj3dpUqdJg1PxRT2RSN/XKdLCPjaYaY=;
        b=B+e/8N2Ko/nEtVP+Wj8zM9q4Cm1Zn6+UDn6VlIp7s5ncZ9YsuAI0O7Q+Qnxy2BZL
        Ek3HXFc+43z0H94PZQ8B0jCKFMu3T9q1Cv2mn+WtJsSYTZGvNqvlsyYhERbPBPbAWfw
        cw48LWRnyQO66q5tOt1wW8fUTlFVFqCEE9yiE2hQ=

任何想法?

非常感謝你的幫助,

保羅

我找到了解決方案。

問題是標題末尾和電子郵件正文之間缺少空格。

它需要2個空格。

$rawEmail = <<<EOE
Subject: {$subject}
MIME-Version: 1.0
Content-type: multipart/alternative; boundary="{$boundary}"{$returnPath}
To: {$to}
From: {$from}


EOE;
    // if we have some html set, lets create a new part and add it
    if ($html)
    {
        $rawEmail .= <<<EOE

--{$boundary}
Content-Type: text/html; charset=iso-8859-1

{$html}

在這種情況下,該點在“ 從”線和“ EOE”線之間。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM