Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change FROM and REPLYTO address in Laravel 5.4

i can't send email with user address as FROM and Reply To

In the FormRequest :

    public function persist()
{
    $reservation = Resa::create(
        $this->only(['nom', 'email', 'phone', 'formule', 'date_arr', 'date_ret', 'nb_adu', 'nb_enf', 'lemessage'])
    );
    Mail::to('[email protected]')
    ->from($reservation->email, $reservation->nom)
    ->replyTo($reservation->email, $reservation->nom)
    ->send(new Reservation($reservation));

}

I have the error :

FatalThrowableError in ReservationForm.php line 48:
Call to undefined method Illuminate\Mail\PendingMail::from()

I tried full of possibility, but I can not change the field FROM and REPLYTO Can you help me ? Thank's

like image 866
Boss COTIGA Avatar asked Mar 07 '17 03:03

Boss COTIGA


1 Answers

The Mail Facade does not implement the replyTo() method anymore. Instead this method has moved to the Mailable class itself. Official documentation proposes to use the build() method to setup the Mailable, however this is not always convenient (eg the replyTo field might be different each time)

However if you still want to use a similar syntax you can use:

$mailable = new myMailableClass;
$mailable->replyTo('[email protected]');

Mail::to('email@tocom')
  ->send($mailable);

For a complete list of available methods on the Mailable class see the Mailable Documentation

like image 143
igaster Avatar answered Sep 25 '22 22:09

igaster