我想使用 mailgun 从我的网页发送和接收电子邮件。
主要问题:Laravel 在 resources\views\pages 上找不到我的 send-email.blade 文件
我为 mailgun 配置了我的 .env 文件。
我错过了什么?这是我的代码;
网页.php
Route::get('/send-email', [App\Http\Controllers\EmailController::class, 'sendEmail']);
应用程序\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 = "[email protected]";
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.";
}
}
配置\服务.php
'mailgun' => [
'domain' => env('MAILGUN_DOMAIN'),
'secret' => env('MAILGUN_SECRET'),
]
配置\邮件.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', '[email protected]'),
'name' => env('MAIL_FROM_NAME', 'app name'),
],
'reply_to' => [
'address' => env('MAIL_FROM_ADDRESS', '[email protected]'),
'name' => env('MAIL_FROM_NAME', 'app name'),
],
应用\邮件\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("[email protected]")->view('email-template');
}
}
电子邮件模板.blade.php
<div class="container">
<p>Hello</p>
<p>
Demo of sending emails through the Mailgun email service.
</p>
</div>
您正在使用->view('email-template);
which 查找文件resources/views/{filename}
你说你的email-template
文件存储在resources\views\pages
因此,您必须使用->view('pages.email-template');
which will look in resources/views/pages/{filename}
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句