LoginSignup
18
31

More than 5 years have passed since last update.

Laravelでmail送信に失敗する場合

Posted at

laravelで下記のようなエラーが発生する場合の参考です。

Swift_TransportException in AbstractSmtpTransport.php line 383:
Expected response code 250 but got code "530", with message "530 5.7.0 Must issue a STARTTLS command first. h8sm146259pfh.49 - gsmtp
"

幾つか英語の解説があります。
http://stackoverflow.com/questions/29100877/trying-to-get-laravel-5-email-to-work

が、自分の場合はうまく行きませんでした。(エラーが変わらない)

で、参考になったのがこちらのページ
https://laravel10.wordpress.com/2015/02/22/%E3%83%A1%E3%83%BC%E3%83%AB%E3%81%AE%E7%92%B0%E5%A2%83%E8%A8%AD%E5%AE%9A/
そのままペタっとでもいけます。

.env
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=465
MAIL_ENCRYPTION=ssl
MAIL_FROM_ADDRESS=your_address@gmail.com
MAIL_FROM_NAME=your_name
MAIL_USERNAME=your_address@gmail.com
MAIL_PASSWORD=your_password
MAIL_PRETEND=false
.mail.php
<?php

return [
    // Mail Driver
    'driver' => env('MAIL_DRIVER', 'smtp'),

    // SMTP Host Address
    'host' => env('MAIL_HOST', 'smtp.mailgun.org'),

    // SMTP Host Port
    'port' => env('MAIL_PORT', 587),

    // Global "From" Address
    'from' => [
        'address' => env('MAIL_FROM_ADDRESS', null),
        'name' => env('MAIL_FROM_NAME', null)
    ],

    // E-Mail Encryption Protocol
    'encryption' => env('MAIL_ENCRYPTION', null),

    // SMTP Server Username
    'username' => env('MAIL_USERNAME', null),

    // SMTP Server Password
    'password' => env('MAIL_PASSWORD', null),

    // Sendmail System Path
    'sendmail' => '/usr/sbin/sendmail -bs',

    // Mail "Pretend"
    'pretend' => env('MAIL_PRETEND', false),
];

=========
.envやmail.phpに設定が正しくされていない場合に発生。
変更後キャッシュクリアをしたほうが良い
'php artisan cache:clear'

Artisanコマンドで全ての設定ファイルを一つにまとめることができます。
'php artisan config:cache'

18
31
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
18
31