5

.env:

MAIL_DRIVER=mail
MAIL_HOST=smtp.mandrillapp.com
MAIL_PORT=587
MAIL_USERNAME=sabin.maharjan456@gmail.com
MAIL_PASSWORD=****************************

Mailer.php:

<?php namespace App\Http\Controllers;

class Mailer{
    public function sendTo($email, $subject, $view, $data = array())
    {
        \Mail::queue($view, $data, function($message) use($email, $subject)
        {
            $message->to($email)->subject($subject);
        });
        return "Mail has been sent";

    }

    public function welcome($formData)
    {
        $subject = "User Message was arrived !";
        $data['name'] = $formData['name'];
        $data['email'] = $formData['email'];
        $data['mobile'] = $formData['mobile'];
        $data['subject'] = $formData['subject'];
        $data['bodymessage'] = $formData['message'];
        $view = 'emails.welcome';
        return $this->sendTo(['sabin.maharjan456@gmail.com'],$subject,$view,$data);
    }
}

Controller:

public function postContactFormRequest(CreateContactFormRequest $request,Mailer $mailer)
{
    $formData = $request->all();
    $this->mailer->welcome($formData);
}

View/blade file:

<!DOCTYPE html>
<html lang="en-US">
<head>
    <meta charset="utf-8">
</head>
<body>
<h2>User Message</h2>
<p><b>Email Address:</b> {{ $email }}</p>
<h4>User Name : {{ $name }}</h4>
<p> Phone Number :{{ $mobile}}</p>
<p>Message :{{ $bodymessage }} </p>
</body>
</html>

I get a continuous error while trying to send email.

Missing argument 1 for Illuminate\Support\Manager::createDriver(), called in /home/robustit/public_html/nic-website/vendor/laravel/framework/src/Illuminate/Support/Manager.php on line 89 and defined

francisco
  • 1,387
  • 2
  • 12
  • 23
sabin maharjan
  • 409
  • 1
  • 8
  • 27

1 Answers1

-1

I have had issues with this until now.

What you want is to check your .env file and make sure your database parameters are right, but also you want these:

CACHE_DRIVER=file SESSION_DRIVER=file QUEUE_DRIVER=sync

For some reason I got these to have empty fields. And then it worked for me!

shabany
  • 799
  • 8
  • 13