使用Laravel连接AWS SES

k97glaaz  于 2023-04-22  发布在  其他
关注(0)|答案(2)|浏览(148)

目前正在处理用户注册表单,该表单(如预期)向注册用户发送电子邮件。
客户决定使用AWS SES,所以我已经配置了这个。

.env

MAIL_DRIVER=smtp
MAIL_HOST=email-smtp.eu-west-1.amazonaws.com
MAIL_PORT=587
MAIL_USERNAME=my_username
MAIL_PASSWORD=my_password
MAIL_ENCRYPTION=null

还定义了以下凭据:

SES_KEY=keyRetrievedFromMyCredentialsInSES
SES_SECRET=passwordRetrievedFromMyCredentialsInSES

还有telnet email-smtp.eu-west-1.amazonaws.com 587 Trying 52.19.235.197... Connected to ses-smtp-eu-west-1-prod-345515633.eu-west-1.elb.amazonaws.com.
这里会出什么问题呢?

gjmwrych

gjmwrych1#

如果没有ADDRESSNAME设置,它可能无法工作。

MAIL_DRIVER=smtp
MAIL_HOST=null
MAIL_PORT=null
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

MAIL_FROM_ADDRESS = 'hello@example.com'
MAIL_FROM_NAME = 'Example'

.env中更改设置后。运行config:cache

php artisan config:cache
gkl3eglg

gkl3eglg2#

检查文档-〉https://laravel.com/docs/7.x/mail
1.安装狂饮

composer require guzzlehttp/guzzle

1.安装AWS SDK for php(laravel)

composer require aws/aws-sdk-php

1.检查.env文件中的值

MAIL_DRIVER=ses
MAIL_HOST=email-smtp.eu-west-1.amazonaws.com  //aws SMTP Settings -> check mail host
MAIL_PORT=465
MAIL_USERNAME=smpt_username  //aws SMTP Settings -> click Create My SMTP Credentials
MAIL_PASSWORD=smpt_password  //aws SMTP Settings -> click Create My SMTP Credentials
MAIL_ENCRYPTION=ssl
MAIL_FROM_ADDRESS=your_email  //aws Email Addresses -> add email address -> send test email (in sendbox mode you can send email only on same email for testing) 
MAIL_FROM_NAME="${APP_NAME}"

AWS_ACCESS_KEY_ID= aws_access_key_id  //create user or in existing user check access key
AWS_SECRET_ACCESS_KEY= secret_access_key  //create user or in existing user check secret key
AWS_DEFAULT_REGION=eu-west-1  //change with your region
AWS_BUCKET=

1.在config/service.php

'ses' => [
       'key' => env('AWS_ACCESS_KEY_ID'),
       'secret' => env('AWS_SECRET_ACCESS_KEY'),
       'region' => env('AWS_DEFAULT_REGION', 'eu-west-1'), // change with your region
   ],

1.清除缓存

php artisan config:cache

相关问题