Я постараюсь внести ясность: я работаю над веб-приложением, использующим Amazon EC2, Amazon S3, Amazon RDS, а теперь и Amazon SES. Я пытаюсь реализовать проверку электронной почты при регистрации. К сожалению, почтовая функция php по какой-то причине не работает на экземплярах amazon EC2, я попытался переустановить sendmail и postfix и безрезультатно заглянул в файл php .ini. Это приводит меня к следующему: https://docs.aws.amazon.com/ses/latest/DeveloperGuide/send-using-sdk-php.html
, который отлично работает, но только если вы запускаете его из оболочки, доступ к которой осуществляется через s sh с использованием шпатлевки.
Using username "ec2-user".
Authenticating with public key "imported-openssh-key"
Last login: Fri Aug 7 05:32:51 2020 from 116.90.72.92
__| __|_ )
_| ( / Amazon Linux AMI
___|\___|___|
https://aws.amazon.com/amazon-linux-ami/2018.03-release-notes/
[ec2-user@ip-172-31-24-178 ~]$ sudo su
[root@ip-172-31-24-178 ec2-user]# php amazon-ses-sample.php
Email sent! Message ID: 010f0173c771a9d3-b9d5e167-7b19-4b42-a550-dce52a8b83d5-000000
[root@ip-172-31-24-178 ec2-user]#
Все мои сценарии php запускаются с сервера apache (httpd), запущенного на экземпляре EC2, который я использую. Скрипты работают нормально, но я пытаюсь включить образец amazon ses (см. Код ниже), он выдает ошибку и не выполняется:
//include 'amazon-ses-sample.php'; <-------**HERE: including this doesn't work.**
?>
Этот скрипт из AWS, который работает, только если вы используете команда: $ php amazon-ses-sample.php
// If necessary, modify the path in the require statement below to refer to the
// location of your Composer autoload.php file.
require '/var/www/aws/aws-autoloader.php';
use Aws\Ses\SesClient;
use Aws\Exception\AwsException;
// Create an SesClient. Change the value of the region parameter if you're
// using an AWS Region other than US West (Oregon). Change the value of the
// profile parameter if you want to use a profile in your credentials file
// other than the default.
$SesClient = new SesClient([
'profile' => 'default',
'version' => '2010-12-01',
'region' => 'us-east-2'
]);
// Replace sender@example.com with your "From" address.
// This address must be verified with Amazon SES.
$sender_email = 'ngudy049@gmail.com';
// Replace these sample addresses with the addresses of your recipients. If
// your account is still in the sandbox, these addresses must be verified.
$recipient_emails = ['ngudy049@gmail.com','ngudy049@gmail.com'];
// Specify a configuration set. If you do not want to use a configuration
// set, comment the following variable, and the
// 'ConfigurationSetName' => $configuration_set argument below.
//$configuration_set = 'ConfigSet';
$nameString = "username3";
$subject = 'Amazon web app sign up test';
$plaintext_body = "This email was sent with Amazon SES using the AWS SDK for PHP.".
"Username: ".$nameString." Password: ".$passwordString."Please click this link to activate your account:".
"http://www.yourwebsite.com/verify.php?email=".$emailString."&hash=".$hashString; // Our message above including the link
$html_body = "<p>Thanks for signing up! Your account has been created, you can login".
" with the following credentials after you have activated your account by pressing the url below.</p>".
"<br>".
"Username: ".$usernameString. "<br>".
"Password: ".$passwordString. "<br>".
"<br>".
"http://3.23.88.212/verify.php?email=".$emailString."&hash=".$hashString; // Our message above including the link;
$char_set = 'UTF-8';
try {
$result = $SesClient->sendEmail([
'Destination' => [
'ToAddresses' => $recipient_emails,
],
'ReplyToAddresses' => [$sender_email],
'Source' => $sender_email,
'Message' => [
'Body' => [
'Html' => [
'Charset' => $char_set,
'Data' => $html_body,
],
'Text' => [
'Charset' => $char_set,
'Data' => $plaintext_body,
],
],
'Subject' => [
'Charset' => $char_set,
'Data' => $subject,
],
],
// If you aren't using a configuration set, comment or delete the
// following line
//'ConfigurationSetName' => $configuration_set,
]);
$messageId = $result['MessageId'];
echo("Email sent! Message ID: $messageId"."\n");
} catch (AwsException $e) {
// output error message if fails
echo $e->getMessage();
echo("The email was not sent. Error message: ".$e->getAwsErrorMessage()."\n");
echo "\n";
}
?>
Я попытался добавить содержимое amazon-ses-sample. php в мои php сценарии, но это не сработало. Работает только если вы используете:
[root@ip-172-31-24-178 ec2-user]# php /var/www/html/amazon-ses-sample.php