daniel-zahariev / php-aws-ses

PHP classes that interfaces Amazon Simple Email Service
307 stars 100 forks source link

Signature V4 not working? #72

Open jane-t opened 4 years ago

jane-t commented 4 years ago

Sorry to trouble you. I have downloaded the latest version using composer.

The following code appears to work eg no errors, but the email never arrives. `$signature_version = SimpleEmailService::REQUEST_SIGNATURE_V4; $region_endpoint = SimpleEmailService::AWS_US_EAST_1; $trigger_error = true; $ses = new SimpleEmailService('AccessKey', 'SecretKey', $region_endpoint, $trigger_error, $signature_version);

$messagetmpl = file_get_contents('email.txt'); $subject = $str = strtok($messagetmpl, "\n"); $userlist = file('email_list.txt'); foreach ($userlist as $line) { // Loop Emails $user = explode(',',$line);

$message = str_replace('{user}',$user[1],$messagetmpl); $message = str_replace('{password}',$user[2],$message); $message = str_replace('{signup}',$user[3],$message); $message = str_replace('{last}',$user[4],$message);

$m = new SimpleEmailServiceMessage(); $m->addTo($user[0]); $m->setFrom('Admin at xxxxxxx@xxxx.org.uk'); $m->setSubject($subject); $m->setMessageFromString($message); echo $user[0].' ',$user[1].'
';

$ses->sendEmail($m);

usleep(200000); // End Loop Emails } echo 'All Done';`

If I change the ses line to just $ses = new SimpleEmailService($key, $secret);

The email arrives, is there something I need to do in the Amazon Management Console which I have not done?

daniel-zahariev commented 4 years ago

Hi @jane-t, did you check if $ses->sendEmail($m); returns an error when you use v4 signature? If there's an issue in the AWS console this error might give you a hint. Have you verified the sender email?

jane-t commented 4 years ago

The sender is verified. If I call the ses set up process with $ses = new SimpleEmailService($key, $secret);

It works fine, it's only when I call it with the V4

I have found the error I am getting

PHP Warning: SimpleEmailService::sendEmail(): Sender - InvalidClientTokenId: The security token included in the request is invalid.

I am not changing the access or secret between the two options.

daniel-zahariev commented 4 years ago

Hm, that's weird. Can't find anything that can lead to this error.

jane-t commented 4 years ago

Is there anything I can put in to help debug why the error is occurring? Could you point me in the right direction to add some echo statements to see what is being sent?

On Tue, 21 Jul 2020 at 13:45, Daniel Zahariev notifications@github.com wrote:

Hm, that's weird. Can't find anything that can lead to this error.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/daniel-zahariev/php-aws-ses/issues/72#issuecomment-661836308, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAHAZWGZAOQPHEFJXR2RBZTR4WEW5ANCNFSM4PDM3Q4A .

-- Jane.

Jane Taubman | www.rjt.org.uk | www.taubman.org.uk | www.fhug.org.uk

daniel-zahariev commented 4 years ago

I'll dig into this tomorrow. In the mean time - have you tried using different credentials?

jane-t commented 4 years ago

I tried setting up a new user with just the AmazonSESFullAccess https://console.aws.amazon.com/iam/home?region=us-east-1#/policies/arn%3Aaws%3Aiam%3A%3Aaws%3Apolicy%2FAmazonSESFullAccess permission, but got the same error message for V4.

On Thu, 23 Jul 2020 at 08:32, Daniel Zahariev notifications@github.com wrote:

I'll dig into this tomorrow. In the mean time - have you tried using different credentials?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/daniel-zahariev/php-aws-ses/issues/72#issuecomment-662860850, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAHAZWFFFC3S653SJ5EJATTR47RRRANCNFSM4PDM3Q4A .

-- Jane.

Jane Taubman | www.rjt.org.uk | www.taubman.org.uk | www.fhug.org.uk

jane-t commented 4 years ago

Did you have any liuck with this problem please?

daniel-zahariev commented 4 years ago

Still can't recreate the issue.

aa6my commented 4 years ago

@jane-t its work, but attachment not working in web/cli. you can check https://github.com/daniel-zahariev/php-aws-ses/issues/73

aa6my commented 4 years ago

@jane-t its work, but attachment not working in web/cli. you can check #73

its work with another method in https://github.com/daniel-zahariev/php-aws-ses/issues/73

vborduja commented 3 years ago

@aa6my @jane-t It works for me: sendMail() and sendMailRaw()