Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Guru5005's avatar

Class 'Swift_Mime_Headers_UnstructuredHeader' not found in Laravel 5.4

I am sending e-mails from laravel app, the e-mail is working fine in localhost, but not working in production server. Note: Hosted the application in Shared Hosting (As its for personal Use)

My Controller

    public function createapplication(Request $request)
    {
    $leaves = Application::create([
    'emp_id' => auth()->user()->id,
    'from_date' => request('from_date'),
    'to_date' => request('to_date'),
    'days' => request('days'),
    'reason' => request('reason')
     ]);

    $fromdate = $request->from_date;
    $to_date = $request->to_date;
    $days = $request->days;
    $reason = $request->reason;

     $data = array('name'=>auth()->user()->name, 'From_date'=>$fromdate, 
      'To_date'=>$to_date, 'Days'=> $days, 'Reason'=>$reason);
     Mail::send('mail.leavesmail', $data, function($message) use ($fromdate, $to_date, $days, 
      $reason){   

     $message->to('example.com', 'example')->subject('Leave Application');
     $message->from('example.com', "example");
      $message->cc(auth()->user()->email);
        });

     return redirect()->back()->with('status', 'Leave Application Submitted Successfully!');

My env file

    MAIL_DRIVER=smtp
    MAIL_HOST=smtp.gmail.com
    MAIL_PORT=587
    [email protected]
    MAIL_PASSWORD=password
    MAIL_ENCRYPTION=tls

Config/mail.php

 <?php



'driver' => env('MAIL_DRIVER', 'smtp'),


'host' => env('MAIL_HOST', 'smtp.mailgun.org'),



'port' => env('MAIL_PORT', 587),



'from' => [
    'address' => env('MAIL_FROM_ADDRESS', '[email protected]'),
    'name' => env('MAIL_FROM_NAME', 'Example'),
],



'encryption' => env('MAIL_ENCRYPTION', 'tls'),



'username' => env('MAIL_USERNAME'),

'password' => env('MAIL_PASSWORD'),



'markdown' => [
    'theme' => 'default',

    'paths' => [
        resource_path('views/vendor/mail'),
    ],
],

];
0 likes
1 reply
Guru5005's avatar
Guru5005
OP
Best Answer
Level 3

The files did not get upload properly, solved it by re uploading all the files.

Please or to participate in this conversation.