Laravel Homestead Swift Cannot send message withou

2019-03-23 08:26发布

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 AbstractSmtpTransport.php line 162:Cannot send message without a sender address

The address is filled in app/config/mail.php:

'from' => array('address' => 'myusername@gmail.com', 'name' => 'hawle'),

5条回答
姐就是有狂的资本
2楼-- · 2019-03-23 08:47

The file: /bootstrap/cache/config.php
The change:

'mail' => array(
            'driver' => 'smtp',
            'host' => 'mail.yourserversiteemail.com',
            'port' => '25',
            'from' =>
            array(
                'address' => 'panel@yourserversiteemail.com',
                'name' => 'sd',
            ),
            'encryption' => 'tls',
            'username' => 'yourUsername',
            'password' => 'yourPass',
            'sendmail' => '/usr/sbin/sendmail -bs',
查看更多
闹够了就滚
3楼-- · 2019-03-23 09:01

In your .env file you will need to set the email address and password of your email account. You also need to set the host and port of the mail server you are using.

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=25
MAIL_USERNAME= ***USER NAME***
MAIL_PASSWORD= ***PASSWORD***
MAIL_ENCRYPTION=tls

Or make sure that everything is complete in your mail.php file (see note below).

'host' => env('MAIL_HOST', 'smtp.gmail.com'),
/*
|--------------------------------------------------------------------------
| SMTP Host Port
|--------------------------------------------------------------------------
|
| This is the SMTP port used by your application to deliver e-mails to
| users of the application. Like the host we have set this value to
| stay compatible with the Mailgun e-mail application by default.
|
*/
'port' => env('MAIL_PORT', 25),
/*
|--------------------------------------------------------------------------
| Global "From" Address
|--------------------------------------------------------------------------
|
| You may wish for all e-mails sent by your application to be sent from
| the same address. Here, you may specify a name and address that is
| used globally for all e-mails that are sent by your application.
|
*/
'from' => ['address' => 'myusername@gmail.com', 'name' => 'hawle'],
/*
|--------------------------------------------------------------------------
| E-Mail Encryption Protocol
|--------------------------------------------------------------------------
|
| Here you may specify the encryption protocol that should be used when
| the application send e-mail messages. A sensible default using the
| transport layer security protocol should provide great security.
|
*/
'encryption' => env('MAIL_ENCRYPTION', 'tls'),

Note: It's better to use the .env file, as you most likely will have a different configuration in your production environment.

If everything is completed and it still doesn't work, it might be caching. You can clear the config cache with this:

php artisan config:cache

Also note:

  • Port 465 is for Gmail. If it does not work, you can use 25.
  • The mail.php file is located at /app/config/mail.php (as OP said).
  • The .env file is located at the root of your project.
  • Mailtrap.io is a service for testing SMTP. It does not really send emails.

As Viktorminator mentioned: Take into consideration creating app passwords and not using your usual pass for this needs. Link for creating passwords myaccount.google.com/apppasswords

查看更多
Evening l夕情丶
4楼-- · 2019-03-23 09:05

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

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

It will fix the problem.

查看更多
在下西门庆
5楼-- · 2019-03-23 09:09

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!');
...
查看更多
家丑人穷心不美
6楼-- · 2019-03-23 09:13

If you don't have access to the .env file, you can add default values to those env calls on app/config/mail.php, like this:

    'from' =>  ['address' => env('MAIL_FROM_EMAIL','do_not_reply@email.com'), 'name' => env('MAIL_FROM_NAME','SpongeBob')],

This approach will try to get the data from the .env file, if there's nothing there, it'll default to whatever you set.

查看更多
登录 后发表回答