2016-08-29 53 views
1

AWS SESサービスでHTML形式のメールを送信するように検索しています。AWS sdk phpを使用してSES経由で未処理のメールを送信

私はこれは私が使用してコントローラのコードでPHP SDK eを使用しています:

.... 
    $to   = "[email protected]"; 
    // You'll need to be able to send as this address in SES 
    $from  = "[email protected]"; 

    // $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: 
[email protected] 
Action: failed 
Final-Recipient: rfc822; [email protected] 
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: <[email protected]west-1.amazonses.com> 
From: [email protected] 
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= 

パオロ

答えて

1

は、私は解決策を見つけた、助けのためにどうもありがとうございます。

問題は、ヘッダーの末尾と電子メールの本文の間にスペースがないことでした。

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ラインからの間です。

関連する問題