John Davidson

php - Laravel notifications - Mailgun - "On Behalf of" in Outlook


The sender in mails recieved in MS. Outlook, sent thru mailgun api looks like this:

[email protected] on behalf of [email protected]

Using ->from (as suggested in the documentation) does not solve it:

return (new MailMessage)->from('[email protected]', '')

When sending a traditional Mail::send() I solve it by...

...adding ->sender('[email protected]', 'Mr Info') to the class:

 Mail::send(['html' => ''], ['data' => $this->details], function ($message) use ($details) {
$message->from(config('mail.from.address'), config(''));
$message->sender(config('mail.from.address'), config(''));

However I can't figure out how I add the ->sender() class to notifications...?

Laravel 8

My Answer:
To send notifications using Laravel with Mailgun, you first need to set up Mailgun as your mail driver in your Laravel application. Here's how you can do it:

1. Install the Mailgun driver package using Composer:

composer require guzzlehttp/guzzle
composer require mailgun/mailgun-php

2. Update your `.env` file with your Mailgun API credentials:


3. Create a notification class in your Laravel application. For example, you can create a new notification using the `php artisan make:notification` command:

php artisan make:notification OrderShipped

4. In your notification class, you can define the notification content and how it should be sent. For example:
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Notification;
use Illuminate\Notifications\Messages\MailMessage;

class OrderShipped extends Notification
use Queueable;

public function via($notifiable)
return ['mail'];

public function toMail($notifiable)
return (new MailMessage)
->line('Your order has been shipped!')
->action('View Order', url('/orders/'.$this->order->id))
->line('Thank you for shopping with us!');

5. To send the notification, you can use the `notify()` method on your notifiable model. For example, if you want to send the notification to a user:
$user->notify(new OrderShipped($order));

That's it! Your Laravel application should now be able to send notifications using Mailgun. Make sure to test your notifications to ensure they are being sent correctly.

Rate this post

3 of 5 based on 9026 votes


© 2024 - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us