Petro Popelyshko
Petro Popelyshko

Reputation: 1379

Amazon Ses SendRawEmail - not delivered

So i ran into a problem with SendRawEmail (Amazon SES), emails is sent but not delivered! Here is my code:

    $phpMail = new PHPMailer();

        $phpMail->addAddress($this->getToEmail(), $this->getToName());
        $phpMail->setFrom($this->getFromEmail(), $this->getFromName());

        $replyTo = $this->getReplyTo();
        if($replyTo){
            $phpMail->addReplyTo($this->getReplyToEmail(), $this->getReplyToName());
        }

        $phpMail->Subject = $subject;
        $phpMail->CharSet = 'UTF-8';
        $phpMail->AltBody = $plainBody;
        $phpMail->Body = $htmlBody;
//        $mail->isHTML(true);

        $phpMail->preSend();

        $rawEmail = array(
            'Source'       => $this->getFromEmail(),
            'Destinations' => array($this->getToEmail()),
            'RawMessage'   => array(
                'Data' => base64_encode($phpMail->getSentMIMEMessage())
            )
        );

    $mail = $this->getSender();
    $command = $mail->getCommand("SendRawEmail", $rawEmail);
    /** @var Aws\Result $result */
    $result = $mail->execute($command);

this result return status 200

    {     "MessageId": "someid",     
           "@metadata": {         
           "statusCode": 200,         
           "effectiveUri": "https:\/\/email.us-east-1.amazonaws.com",        
           "headers": {             "x-amzn-requestid": "somegenerated id",             
           "content-type": "text\/xml",             
            "content-length": "338",             
"date": "Tue, 11 Aug 2015 07:33:03 GMT"         } 

But if i send emails with SendEmail its delivered

   $mail      = $this->getSender();
        $message   = array();
        $message['Source'] = "{$this->getFromName()} <{$this->getFromEmail()}>";
        $message['Destination']['ToAddresses'][] = "{$this->getToName()} <{$this->getToEmail()}>";
        $message['Message'] = array(
            'Subject'    => array(
                'Data' => $this->getSubject()
            ),
            'Body' => array(
                        'Text'  => array('Data' => $this->getBodyPlain()),
                        'Html'  => array('Data' => $this->getBodyHtml())
            )
        );
        $replyTo = $this->getReplyTo();
        if($replyTo){
            $message['ReplyToAddresses'] = $replyTo;
        }
        try {
            $command = $mail->getCommand("SendEmail", $message);
            /** @var Aws\Result $result */
            $result = $mail->execute($command);

I need to send letters via SendRawEmail because i need to set custome headers, but how to debug my problem, any suggestions??

Upvotes: 1

Views: 2266

Answers (1)

Petro Popelyshko
Petro Popelyshko

Reputation: 1379

So i found an error I need to send email without base64_encode because i don't have attachments

Upvotes: 1

Related Questions