Laravel send email with multiple senders - laravel

I have a Laravel application that send two different kind of emails from different senders. One for the users and other one for the admins.
The emails for the admins works fine, i'm using smtp gmail.
How can I send the other type of emails using different sender? Thank you.

You can use the from() function in the mailable or the facade (if Mailables aren't in your version of Laravel):
Docs: https://laravel.com/docs/5.7/mail#configuring-the-sender

Related

Laravel Mail or Notification? which one should use for email sending? and Why?

I'm new in laravel. I have to use email feature in my project. In Laravel Docs, I got Mail and Notification options for sending email feature. Now I want to know which one should be used and why?
Please Note: I will use ShouldQueue as well.
If you want to send the information via just one channel, say email only, then use Mailable. If you are likely to send the information as email or SMS, some other medium or multiple(eg. email and SMS), your best bet is to use Notification.
You should use Mailable, if each email you send out has different layout. Mailable is a very flexible way to send emails. And it's more customizable than Notification.
Notification is useful if you have to send a predefined layout in differents channel.
You can customize notifications layout, but it's not advisable as it's out of scope to have more than one layout of notification.
According to this laracasts video
"a general rule of thumb, what's nice about Notifications is you are notifying the user in response to some action that took place on the website, so they made a payment, they close their account they liked something these are all responses to an action."
I use the Mail facade for marketing, for example: to inform the new features in our website, inform some special day is coming soon, etc.

is it possible to notify all users using Laravel notification with pusher?

Is it possible to create/send notification(s) to all users when there is new announcement.
I want all users to be notified using the database notification.
Since most of the tutorials I have seen are all email notification, is this possible? Please attach links or any idea on how I could implement this.
Literally in the documentation:
Alternatively, you may send notifications via the Notification facade.
This is useful primarily when you need to send a notification to
multiple notifiable entities such as a collection of users. To send
notifications using the facade, pass all of the notifiable entities
and the notification instance to the send method:
Notification::send($users, new InvoicePaid($invoice));
So yes, you can send to all user by getting them from the database and sending a notification using the facade.
For example:
Notification::send(User::all(), new InvoicePaid($invoice));

Send Mailchimp Campaign to Single Email Address

I'm creating custom emails (many customizations) in MailChimp campaign builder. Looks like the only option to send is via a campaign, which I'd need to manually upload a list of email addresses. I honestly just want to use the builder to send a quality form email, that I customize for each recipient.
Is it possible to send an email to a specific email address without building a list, etc? This will probably be a one-time thing.
You can send campaign to single email address in mailchimp through this method. However you can't send the same campaign more than once to same email address.
create an automation email with API 3.0 as trigger.
Now, to send a campaign, make POST call to the given url with email address in your mailchimp
https://us19.api.mailchimp.com/3.0/automations/********/emails/********/queue
Now, To call that api you need to add HTTP BAsic Auth or OAuth 2 to API Request. See this answer MailChimp 3.0 HTTP POST Json Example
There's also a npm module to make life easier https://npmjs.com/package/mailchimp-api-v3
This is just a workaround as mailchimp was not built for single emails. In the longer run I'd suggest you to look into mandrill, sendgrid or other transactional email tool.
You are better off using Mandrill, MailChimp's transactional email app, to send one off emails. You can still use or at least make use of MailChimp campaigns but you can send one off emails that are customised and you do not need to send to a list

Laravel 5.3 Notification Vs Mailable

I am a little confused about whether to use Laravel's Notification or Mailable class. From what I understand, Mailables are used to send only emails whereas Notifications can be used to send emails and sms. In my application, I dont have plans to send sms notifications for now, so I am confused if I should just use the Mailable class in this case. My questions are:
If I am only going to be sending emails notifications, is it
better for me to use Mailables instead of Notifications?
If each emails have different html layout, then would Mailable be
the better option?
Even if all emails are Notification emails in nature, does it still make
sense to send them using Mailables instead of Notifications?
Can someone tell me the main difference between these 2 and how should we decide on which method to choose when sending emails in Laravel 5.3.
Although it is not in the documentation, as of Laravel 5.3.7, the Notifications mail channel can work with Mailable objects in addition to the notification MailMessage objects.
Therefore, you can create all your emails as Mailable objects, and if you decide to send them via Notifications, you would just have your toMail() method return the Mailable objects you've already made.
Yes, definitively, if each email layout is different, you should use Mailable
Mailable is the new way to send emails, easier than before. More customizable than Notifications.
Notification is very nice if you want to send a predefined layout in differents channel ( Mail, SMS, Slack, etc )
You can customize notifications layout, but having 1 layout by notification is going to get more difficult... it is just not the use case for notifications

How to know mail send or not send in laravel and which recipient is not getting it?

Hi I am using the bellow function, can you please guide me how can I use Mail::failures(); in it
Mail::send('emails.caregiversetprimary', $templateArray, function($message)use($email)
{
$message->to($email, 'username')->subject('my subject');
});
Mail::failures(); < ====== this gives me black array as I have used wrong email
I am using laravel 4.1
tl;dr
You can know which recipients the email has been sent to but no which recipients have received it.
details
You need a better understanding of how mail servers work. From a Laravel point of view, there is no way (or at least not a simple one*) of knowing which recipients got the email. Its a matter of how mail protocol works. You may know which recipients the message has been sent to but no which recipients actually got it.
With Mail::failures() you get a list of recipients to which Laravel tried to send the email but it failed on actually sending it. But again, if it has been sent there is no straightforward way to known if the mail reached their inbox or no.
*If you happend to use Mailgun, Mandrill or any other 3rd party software then you are not dealing with a mail server 'per se' but with an API service. May be you could check the mail service provider documentation to research if they perform any kind of delivery tracking that you can programatically check.

Resources