【问题标题】:Connecting to AWS SES with Laravel使用 Laravel 连接到 AWS SES
【发布时间】:2018-09-13 01:07:53
【问题描述】:

目前正在处理用户注册表单,该表单(如预期的那样)向注册用户发送电子邮件。

客户决定使用 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.

这里可能出了什么问题?

【问题讨论】:

  • 您是否验证了您在亚马逊的send 地址?
  • @Ohgodwhy 是的,这是经过验证的。原来问题是我没有设置:MAIL_DRIVER=ses

标签: laravel amazon-web-services email amazon-ses


【解决方案1】:

检查文档 -> https://laravel.com/docs/7.x/mail

  1. 安装guzzle
    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('Secret access key'),
       'region' => env('AWS_SECRET_ACCESS_KEY', 'eu-west-1'), // change with your region
   ],
  1. 清除缓存
php artisan config:cache

【讨论】:

    【解决方案2】:

    如果没有 ADDRESS 和 NAME 设置,它可能无法工作。

    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
    

    【讨论】:

      猜你喜欢
      • 2019-07-19
      • 2020-06-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-04
      • 1970-01-01
      • 1970-01-01
      • 2018-06-26
      相关资源
      最近更新 更多