Laravel Homestead Swift Cannot send message without a sender address

前端 未结 14 981
予麋鹿
予麋鹿 2020-12-08 19:09

I get this error with stock email settings in Laravel 5.1 Homestead when I try to send a password reset mail.

Swift_TransportException in AbstractSmtpTransp         


        
相关标签:
14条回答
  • 2020-12-08 19:56

    Maybe someone is using laravel 6
    Its problem is "Cannot send message without a sender address" so there is no email address to send the email in .env file

    Just add sender email address

    MAIL_DRIVER=smtp
    MAIL_HOST=smtp.mailtrap.io
    MAIL_PORT=2525
    MAIL_USERNAME=your_username
    MAIL_PASSWORD=your_password
    MAIL_ENCRYPTION=null
    MAIL_FROM_ADDRESS=example@gmail.com **here**
    MAIL_FROM_NAME="${APP_NAME}"
    

    I didn't change anything in the mail.php file, its work for me in laravel 6, after that run

    php artisan config:cache
    
    0 讨论(0)
  • 2020-12-08 20:00

    I just solved this in Laravel 7.9. I'm using mailtrap.io and I believe the issue was a missing MAIL_ENCRYPTION=tls variable. This variable is not present in the mailtrap.io sample config OR the .env.example file.

    Here are my .env settings:

    MAIL_MAILER=smtp
    MAIL_HOST=smtp.mailtrap.io
    MAIL_PORT=2525
    MAIL_USERNAME=[found in mailtrap settings]
    MAIL_PASSWORD=[found in mailtrap settings]
    MAIL_ENCRYPTION=tls
    MAIL_FROM_ADDRESS=me@mydomain.com
    MAIL_FROM_NAME="${APP_NAME}"
    
    0 讨论(0)
  • 2020-12-08 20:00

    If you are using gmail account, settings are different now. Config .env:

    MAIL_DRIVER=smtp
    MAIL_HOST=smtp.gmail.com
    MAIL_PORT=587
    MAIL_USERNAME=example@gmail.com
    MAIL_PASSWORD=password
    MAIL_ENCRYPTION=tls
    MAIL_FROM_ADDRESS=example@gmail.com
    

    You can also ssl encryption and then following settings:

    MAIL_ENCRYPTION=ssl
    MAIL_PORT=465
    

    And after setting everything run:

    php artisan config:cache
    

    You may also need to check on option "Less secure app access" on https://myaccount.google.com/security.

    0 讨论(0)
  • 2020-12-08 20:02

    Make sure you have set the 'from' in app/config/mail.php

    'from' => ['address' => 'myname@gmail.com', 'name' => 'myname']
    

    It will fix the problem.

    0 讨论(0)
  • 2020-12-08 20:03

    error was still occure. after settings and run commands

    php artisan view:clear;
    php artisan config:cache;
    php artisan cache:clear;
    php artisan route:cache;
    

    check the code

    \Illuminate\Support\Facades\Mail::send('layouts.mail', [ 'content' => 'testmail'],    function ($m) use ($msg2){
    $m->from('abc@gmail.com', 'ABC'); 
    // this line was env('MAIL_FROM_ADDRESS') ; cant read from .env
    $m->to('xyz@gmail.com', 'XYZ')->subject('TestMailSubject!');
    ...
    
    0 讨论(0)
  • 2020-12-08 20:06

    Don't forgot also to clear config cache ! it was the problem where I was facing !

    php artisan config:cache
    
    0 讨论(0)
提交回复
热议问题