AWS SES PHP SDK Problem

0

I used the example SES code given to send an SES email through PHP by Amazon (https://docs.aws.amazon.com/ses/latest/DeveloperGuide/send-using-sdk-php.html). Using PHP and the SES example in my application, the php file works perfectly fine when I call it through "php sendpass.php" in the console (email sends and console gets confirmation). But when I open that same page in a browser, the line "$result1 = $SesClient->sendEmail([]);" causes a "500 internal server error" and fails to execute the code. Even removing the meat from the function causes this problem, I've no where to turn for information on this because it seems like no one else is having this problem, is it a problem with the SDK?

  • I'm guessing this is an AWS credential issue but that is just a guess without a proper error message. Check your webserver's log file for a better error message?

1개 답변
2
수락된 답변

When you run it locally, you have a different environment than when it runs via your web browser and your web server. Make sure you have your AWS credentials properly available to your script. You also should be able to look in your server error logs to see details of what's causing the error. Finally, you can surround the call to sendEmail([...]) with a try { sendEmail([...]); } catch (Exception $e) { echo "<pre>"; print_r($e); echo "</pre>"; } to see if that catches the error and displays what's going on.

For our purposes, we have the AWS credentials in a text file on the server in a non-public path that the script can access and then we use the CredentialProvider to ... provide the credentials. ;)

use Aws\Credentials\CredentialProvider;
use Aws\Ses\SesClient;

$provider = CredentialProvider::ini('default', '/path/to/credentials.file');
$provider = CredentialProvider::memoize($provider);

$sesClient = SesClient::factory([
  'region' => 'us-east-1',
  'version' => 'latest',
  'credentials' => $provider,
]);
Purdy
답변함 2년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠