2

I am currently catching an exception for when an identity is not verified using the following code -

use Aws\Ses\SesClient;
use Aws\Ses\Exception;

try {
       $result = $ses->sendEmail($data);
} catch (Exception $e) {

    echo $e->getResponse();

}

It prints out the following -

PHP Fatal error:  Uncaught exception 'Aws\Ses\Exception\SesException' 
with message 'Error executing "SendEmail" on "https://email.us-
west-2.amazonaws.com"; AWS HTTP error: Client error: `POST 
https://email.us-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>MessageReje (truncated...)
    MessageRejected (client): Email address is not verified. The 
following identities failed the check in region US-WEST-2: 
arn:aws:ses:us-west-2:**************** - <ErrorResponse 
xmlns="http://ses.amazonaws.com/doc/2010-12-01/">
    <Error>
    <Type>Sender</Type>
    <Code>MessageRejected</Code>
    <Message>Email address is not verified. The following identities 
failed the check in region US-WEST-2: arn:aws:ses:us-
west-2:************</Message>
    </Error>
  <RequestId>*****************</RequestId>
</ErrorResponse>

exception 'GuzzleHttp\Exception\ClientException' with  in /var/www
/html/data/aws/Aws/WrappedHttpHandler.php on line 159

I cannot get any of the methods outlined on the following page to print out anything different -

http://docs.aws.amazon.com/aws-sdk-php/v2/api/class-Aws.Ses.Exception.SesException.html

Any ideas how I can get an actual error code out of this exception so that I can take the appropriate action in the rest of my script?

user1145643
  • 896
  • 5
  • 15
  • 26
  • This may help http://stackoverflow.com/questions/22128800/amazon-ses-email-address-is-not-verified – Amit Ray Jul 11 '16 at 18:59
  • Are you sure you are using the correct namespace? `Aws\Ses\Exception\SesException` is shown in the documentation. You might want to alias the Exception one as @Dekel hints at. Since you are namespacing `Aws\Ses\Exception` you can try to catch for `SesException` and handle it there. – CGSmith105 Jul 14 '16 at 15:13

3 Answers3

0

In order to catch all exceptions you better use

} catch (\Exception $e) {

To make sure you don't get the wrong Exception class from the wrong namespace.

Regarding the problem that you are hitting - when using Amazon SES to send Emails you must first verify your email/domain (note that any of From, source, sender, return-path headers can cause you a problem if not verified).

If you can post some information regarding your $ses object or the $data you use it might help.

Dekel
  • 60,707
  • 10
  • 101
  • 129
0

Class MessageRejectedException Indicates that the action failed, and the message could not be sent. Check the error stack for more information about what caused the error.

Exception
    Extended by RuntimeException
        Extended by Aws\Common\Exception\RuntimeException implements Aws\Common\Exception\AwsExceptionInterface
            Extended by Aws\Common\Exception\ServiceResponseException
                Extended by Aws\Ses\Exception\SesException
                    Extended by Aws\Ses\Exception\MessageRejectedException

Try this -> use Aws\Ses\Exception\MessageRejectedException; or use Aws\Ses\Exception\SesException; and replace class name into catche block

Bcause Aws\Ses\Exception is namespace of class MessageRejectedException. you have to use class with namespace ,not only namespace.

use Aws\Ses\SesClient;
use Aws\Ses\Exception\MessageRejectedException;

try {
       $result = $ses->sendEmail($data);
} catch (MessageRejectedException $e) {

    echo $e->getResponse();

}

I hope helped. Good luck

Vanya Avchyan
  • 880
  • 7
  • 24
0

you can use $e->getAwsErrorCode();

Methods inherited from Aws\Exception\AwsException __construct(), __toString(), get(), getAwsErrorCode(), getAwsErrorMessage(), getAwsErrorShape(), getAwsErrorType(), getAwsRequestId(), getCommand(), getRequest(), getResponse(), getResult(), getStatusCode(), getTransferInfo(), hasKey(), isConnectionError(), isMaxRetriesExceeded(), search(), setMaxRetriesExceeded(), setTransferInfo()

You can see the SesExeption API from AWS link is here: https://docs.aws.amazon.com/aws-sdk-php/v3/api/class-Aws.Ses.Exception.SesException.html

Tyler2P
  • 2,324
  • 26
  • 22
  • 31
aKe
  • 1