Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Reply-to" field in Laravel mail is not working

Tags:

php

email

laravel

I need help to figure out how to set the reply-to field in app/config/mail.php. I'm using Laravel 4 and it's not working. This is my app/config/mail.php:

<?php  return array(     'driver' => 'smtp',     'host' => 'smtp.gmail.com',     'port' => 587,     'from' => [         'address' => '[email protected]',         'name' => 'E-mail 1'     ],     'reply-to' => [         'address' => '[email protected]',         'name' => 'E-mail 2'     ],     'encryption' => 'tls',     'username' => '[email protected]',     'password' => 'pwd',     'pretend' => false, ); 
like image 982
cawecoy Avatar asked Feb 07 '14 16:02

cawecoy


People also ask

How do I know if my mail is working in Laravel?

wrap it in a try catch instead, if exception not caught email is sent, otherwise it failed, try { Mail::to($userEmail)->send($welcomeMailable); } catch (Exception $e) { //Email sent failed. }

What is mailable Laravel?

Laravel provides a clean, simple email API powered by the popular Symfony Mailer component. Laravel and Symfony Mailer provide drivers for sending email via SMTP, Mailgun, Postmark, Amazon SES, and sendmail , allowing you to quickly get started sending mail through a local or cloud based service of your choice.

Can we use PHP mail function in Laravel?

Laravel provides a clean, simple API over the popular SwiftMailer library. The mail configuration file is app/config/mail. php , and contains options allowing you to change your SMTP host, port, and credentials, as well as set a global from address for all messages delivered by the library.


1 Answers

Pretty sure it doesn't work this way. You can set the "From" header in the config file, but everything else is passed during the send:

Mail::send('emails.welcome', $data, function($message) {     $message->to('[email protected]', 'John Smith')         ->replyTo('[email protected]', 'Reply Guy')         ->subject('Welcome!'); }); 

FWIW, the $message passed to the callback is an instance of Illuminate\Mail\Message, so there are various methods you can call on it:

  • ->from($address, $name = null)
  • ->sender($address, $name = null)
  • ->returnPath($address)
  • ->to($address, $name = null)
  • ->cc($address, $name = null)
  • ->bcc($address, $name = null)
  • ->replyTo($address, $name = null)
  • ->subject($subject)
  • ->priority($level)
  • ->attach($file, array $options = array())
  • ->attachData($data, $name, array $options = array())
  • ->embed($file)
  • ->embedData($data, $name, $contentType = null)

Plus, there is a magic __call method, so you can run any method that you would normally run on the underlying SwiftMailer class.

like image 198
Colin Avatar answered Oct 03 '22 02:10

Colin