0

When I try to send mails via Laravel Mail class, I get the following error:

Symfony \ Component \ Debug \ Exception \ FatalThrowableError

(E_RECOVERABLE_ERROR) Type error: Too few arguments to function Swift_Transport_EsmtpTransport::__construct(), 0 passed in /[...]/CustomerCenter/database/factories/vendor/swiftmailer/swiftmailer/lib/classes/Swift/SmtpTransport.php on line 37 and at least 3 expected

I have created a mail class using php artisan make:mail Contact, created the blade view 'contact' in the directory mails and created a controller, called in web.php route file.

The Contact class looks like this:

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;

class Contact extends Mailable {
    use Queueable, SerializesModels;

    /**
     * Create a new message instance.
     *
     */
    public function __construct() {
        //
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build() {
        return $this->view('emails.contact');
    }
}

This is my email configuration - used Config::get('mail')

array:9 [▼
  "driver" => "smtp"
  "host" => "xxx.kasserver.com"
  "port" => "25"
  "from" => array:2 [▼
    "address" => "mail@example.com"
    "name" => "Example"
  ]
  "encryption" => null
  "username" => "xxx"
  "password" => "***"
  "sendmail" => "/usr/sbin/sendmail -bs"
  "markdown" => array:2 [▼
    "theme" => "default"
    "paths" => array:1 [▼
      0 => "/[...]/resources/views/vendor/mail"
]
  ]
]

In the Controller file I call the Mail class this way:

\Mail::to('mail@example.com')->send( new Contact );

I already checked those questions:

I already executed:

  • php artisan config:clear
  • php artisan vendor:publish

I'm confused, I did the same a explained in this tutorial video: https://laracasts.com/series/laravel-from-scratch-2017/episodes/26

Community
  • 1
  • 1
DaFunkyAlex
  • 1,859
  • 2
  • 24
  • 36

1 Answers1

0

Ok, for some reason the include path was: database/factories/vendor/swiftmailer but it should have been vendor/swiftmailer.

I did not realize that. I guess my FTP sync program copied all the vendor stuff to database/factories. Deleting the stuff made laravel to throw an exception of the missing file. So now I knew what to do:

A simple

composer dump-autoload

fixed the problem...

DaFunkyAlex
  • 1,859
  • 2
  • 24
  • 36