Laravel 9.x 找不到视图文件

Laravel 9.x cannot find the view file

我想使用 mailgun 从我的网页发送和接收电子邮件。

主要问题:Laravel 在 resources\views\pages

上找不到我的发送-email.blade 文件

我为 mailgun 配置我的 .env 文件。

我错过了什么?这是我的代码;

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');
    }
}

电子邮件-template.blade.php

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

您正在使用 ->view('email-template);resources/views/{filename}

中查找文件

你说你的 email-template 文件存储在 resources\views\pages

因此您必须使用 ->view('pages.email-template');,它将查找 resources/views/pages/{filename}