phpemaillaravellaravel-5.1

'Object of class Illuminate\Mail\Mailer could not be converted to string'


I am trying to send an e-mail confirmation for registration. I have created app>Mailers>AppMailer.

class AppMailer {

  protected $mailer;

  protected $from = 'admin@example.com';

  protected $to;

  protected $view;

  protected $data = [];


  public function __construct(Mailer $mailer)
  {
    $this->$mailer = $mailer;   // Line 23
  }

However, I am getting an error:

ErrorException in AppMailer.php line 23:

Object of class Illuminate\Mail\Mailer could not be converted to string


Solution

  • Set $this->mailer, not $this->$mailer.


    So instead of this:

    $this->$mailer = $mailer;
        // ^
    

    Use this:

    $this->mailer = $mailer;