Mail Config
Default from address
You can set a global from
address in config/mail.php
instead of setting it each time on your mailables.
config/mail.php
Default to address
You might want to store email addresses of site owner in a config file so you can deliver admin emails to them through mailables.
Warning!
Do not create a
to
key in theconfig/mail.php
file! This is reserved as a universal delivery address for development/testing. Doing this will override all delivery addresses on the mailables.
In the example below we will keep our ‘internal’ email addresses in a site
key.
config/mail.php
You should know!
Note: the email address array keys are different for senders and recipients. Use associative array for every recpient with ‘email’ and ‘name’ keys.
In your mailable you can now use the site owner email address.
Alternatively, you could use the config(mail.from)
address to set the recipient as the site owner. This saves having to create a custom key in the config file but prevents you from directing message to a different address than the sender address.
Sending emails to a list
A mail instance relates to a single email. This means the to
method will append each address to the recipients list for that email - it will not send a new email for each address!
To send an individual email to each person you need to loop over the recipients and re-create the mailable instance for each recipient.
Gmail settings
See how to use gmail with laravel.