Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

169
Views
Agregar encabezados al correo electrónico enviado como una notificación de Laravel

¿Alguien sabe cómo agregar encabezados a los correos electrónicos enviados a través del Sistema de notificación de Laravel ?

¡No estoy hablando de las clases Mailable donde puedo establecer el encabezado a través del método withSwiftMessage() !

También me gustaría seguir usando MailMessage una vez que tenga muchos correos electrónicos creados con los métodos line , ¡ greetings !

¿Alguien tiene alguna pista?

¡Ahí está mi código en caso de que alguien necesite ver algo!

 <?php namespace PumpMyLead\Notifications\Tenants\Auth; use Illuminate\Bus\Queueable; use Illuminate\Notifications\Notification; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Notifications\Messages\MailMessage; class AccountActivation extends Notification { use Queueable; /** * Create a new notification instance. * * @return void */ public function __construct() { // } /** * Get the notification's delivery channels. * * @param mixed $notifiable * @return array */ public function via($notifiable) { return ['mail']; } /** * Get the mail representation of the notification. * * @param mixed $notifiable * @return \Illuminate\Notifications\Messages\MailMessage */ public function toMail($notifiable) { return (new MailMessage) ->subject('My email subject') ->greeting('Just a greeting') ->line('Line 1') ->line('Line 2') ->action('CTA wanted', 'http://www.pumpmylead.com') ->line('Byebye'); } }

¡Gracias por adelantado!

about 4 years ago · Santiago Trujillo
3 answers
Answer question

0

En realidad, he encontrado 2 formas de agregar encabezados.

Cuando la notificación se envía a través del canal de correo, se activa un evento Illuminate\Mail\Events\MessageSending .

Añádele un oyente. En handle() obtendrá el objeto Swift_Message .

O en el método register() de AppServiceProvider , anule MailChannel con el suyo propio y agregue el encabezado en el método send() .

 $this->app->bind( \Illuminate\Notifications\Channels\MailChannel::class, MyMailChannel::class );
about 4 years ago · Santiago Trujillo Report

0

En ./app/Notifications/myNotification.php, agrega este código en tu función __construct():

 $this->callbacks[]=( function($message){ $message->getHeaders()->addTextHeader('x-mailgun-native-send', 'true'); });

Reemplace "x-mailgun-native-send" con cualquier encabezado que desee agregar y 'true' con el valor deseado.

Consulte https://github.com/laravel/ideas/issues/475

about 4 years ago · Santiago Trujillo Report

0

Aquí hay una alternativa moderna de 2022 si lo anterior no funciona, probado en Laravel 8.

usando withSwiftMessage()

 public function toMail($notifiable) { return (new MailMessage) ->subject($subject) ->greeting($greeting) ->line($line1) ->line($line2) ->withSwiftMessage(function($message) use ($value1, $value2) { $message->getHeaders()->addTextHeader('X-MJ-CustomID', json_encode([ 'key1' => $value1, 'key2' => $value2, ])); }) }
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!