Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Laravel 9.x cannot find the view file

I want to send and receive emails from my webpage using mailgun.

Main problem : Laravel cannot find my send-email.blade file on resources\views\pages

I configure my .env file for mailgun.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

What I am missing? Here is my codes;

The Error I get

web.php

Route::get('/send-email', [App\Http\Controllers\EmailController::class, 'sendEmail']);

app\http\controller\EmailController.php

namespace App\Http\Controllers;

use App\Mail\HelloEmail;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Mail;

class EmailController extends Controller
{
    public function sendEmail()
    {
        $reveiverEmailAddress = "example@gmail.com";

        Mail::to($reveiverEmailAddress)->send(new HelloEmail);

        if (Mail::failures() != 0) {
            return "Email has been sent successfully.";
        }
        return "Oops! There was some error sending the email.";
    }
}

config\services.php

 'mailgun' => [
        'domain' => env('MAILGUN_DOMAIN'),
        'secret' => env('MAILGUN_SECRET'),
    ]

config\mail.php

    'mailers' => [
        'smtp' => [
            'transport' => 'smtp',
            'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
            'port' => env('MAIL_PORT', 587),
            'encryption' => env('MAIL_ENCRYPTION', 'tls'),
            'username' => env('MAIL_USERNAME'),
            'password' => env('MAIL_PASSWORD'),
            'timeout' => null,
        ],
    ],


  'from' => [
        'address' => env('MAIL_FROM_ADDRESS', 'myemail@Example.com'),
        'name' => env('MAIL_FROM_NAME', 'app name'),
    ],
    'reply_to' => [
        'address' => env('MAIL_FROM_ADDRESS', 'myemail@Example.com'),
        'name' => env('MAIL_FROM_NAME', 'app name'),
    ],

app\mail\hellomail.php

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;

class HelloEmail extends Mailable
{
    use Queueable, SerializesModels;
    public function __construct()
    {
        //
    }
    public function build()
    {
      
        return $this->from("support@example.com")->view('email-template');
    }
}

email-template.blade.php

<div class="container">
    <p>Hello</p>
    <p>
        Demo of sending emails through the Mailgun email service.
    </p>
</div>

>Solution :

You’re using ->view('email-template); which looks for the file in resources/views/{filename}

You say your email-template file is stored in resources\views\pages

Therefore you have to use ->view('pages.email-template'); which will look in resources/views/pages/{filename}.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading