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?
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.
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