4

I am updating code from laravel 4 to laravel 5

In laravel 4 there is mail functionality implemented with some code like below

Mail::send('emailtemplate.sample', $content_data, function ($message) use ($to_mail, $email_data, $from_name) {
            $message->from('admin@domain.com', 'admin')->to($to_mail)->subject($email_data->subject);                
            $headers = $message->getHeaders();
            $headers->addTextHeader('X-MC-PreserveRecipients', 'false');
        });

I don't know how to replace $headers = $message->getHeaders(); and $headers->addTextHeader('X-MC-PreserveRecipients', 'false'); in laravel 5 mail functionality

If anyone knows, then please suggest

Rupal Javiya
  • 591
  • 5
  • 14
  • is the debug mode set to true? – Nishant Solanki Mar 17 '15 at 12:06
  • Are you getting an error when you attempt this code? A quick glance at Laravel 5's code seems to indicate these same methods are still available and should work the same. – jszobody Mar 17 '15 at 12:07
  • @jszobody, I have not tried still, but is there any reference when I can look into it to just confirm myself about this is still true and working? – Rupal Javiya Mar 17 '15 at 12:10
  • @NishantSolanki, yes it is. but I haven't run my email function still. as I am missing its code(this header one) itself – Rupal Javiya Mar 17 '15 at 12:11
  • 1
    The `getHeaders()` method is being called on `Swift_Message` which isn't part of Laravel, it's a third-party component. So even though Laravel 5 has changed, Swift hasn't and should continue working like before. You can browse the source code to confirm. Go test your code and come back if you experience a problem. – jszobody Mar 17 '15 at 12:12
  • give this a try .. http://stackoverflow.com/questions/17465746/custom-email-headers-in-laravel-4 – Nishant Solanki Mar 17 '15 at 12:30
  • @jszobody, yes its good clarification. I have just tested and it works as you mentioned. Thanks – Rupal Javiya Mar 17 '15 at 12:46

1 Answers1

1

As jszobody mentioned,

The getHeaders() method is being called on Swift_Message which isn't part of Laravel, it's a third-party component. So even though Laravel 5 has changed, Swift hasn't and should continue working like before.

Rupal Javiya
  • 591
  • 5
  • 14