gpt4 book ai didi

php - 拉维尔 6 : Cannot send message without a sender address

转载 作者:行者123 更新时间:2023-12-05 01:13:01 25 4
gpt4 key购买 nike

为什么我尝试从联系人发送电子邮件到我的 mailtrap 时收到此错误 Error message image

这是我的网络路由 routes\web.php

Route::get('contact','ContactFormController@create');

Route::post('contact','ContactFormController@store');

这是我的.env

APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:4Lxefu/REQw/cgLLiwCkXD5HPV6HbbwzRF93N1ZNYvI=
APP_DEBUG=true
APP_URL=http://localhost

LOG_CHANNEL=stack

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=

BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=f65b067cdc6edc
MAIL_PASSWORD=3556eea6c9ad58
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=null
MAIL_FROM_NAME="${APP_NAME}"

AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1

MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

这是我的 Controller app\Http\Controllers\ContactFormController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

// ! IMPORT
use App\Mail\ContactFormMail;
use Illuminate\Support\Facades\Mail;

class ContactFormController extends Controller
{
//

public function create(){
return view('contact.create');
}

public function store(){

$data = request()->validate([
'name'=> 'required',
'email'=> 'required|email',
'message'=> 'required',
]);

// ! Create Mail here

Mail::to('test@test.com')->send(new ContactFormMail());
// dd(request()->all());
}
}

这是我的 contact.blade.php resources\views\contact\create.blade.php

@extends('layouts.app')

@section('content')
<div class="container">
<div class="card">
<div class="card-body">
<div class="card-title"><h1>Contact Form Email</h1></div>
<form action="/contact" method="POST">
<div class="form-group">
<label for="name">Name</label>
<input type="text" name="name" value="{{old('name')}}" class=" form-control">
<div>{{$errors->first('name')}}</div>
</div>

<div class="form-group">
<label for="email">Email</label>
<input type="email" name="email" value="{{old('email')}}" class=" form-control">
<div>{{$errors->first('email')}}</div>
</div>

<div class="form-group">
<label for="message">Message</label>
<textarea name="message" id="message" cols="30" rows="10" class=" form-control"></textarea>
<div>{{$errors->first('message')}}</div>
</div>
@csrf
<button type="submit" class="btn btn-primary">Send Message</button>
</form>
</div>
</div>
</div>
@endsection

这是我的 contact-form.blade.php resources\views\emails\contact\contact-form.blade.php

@component('mail::message')
# Introduction

The body of your message.

@component('mail::button', ['url' => ''])
Button Text
@endcomponent

Thanks,<br>
{{ config('app.name') }}
@endcomponent

这是我的邮件 app\Mail\ContactFormMail.php

<?php

namespace App\Mail;

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

class ContactFormMail extends Mailable
{
use Queueable, SerializesModels;

/**
* Create a new message instance.
*
* @return void
*/
public function __construct()
{
//
}

/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->markdown('emails.contact.contact-form');
}
}

请检查我是否做错了什么,我是否需要托管此应用程序才能使邮件功能在 mailtrap 上运行?上面附有错误消息图像。

最佳答案

ContactFormMail 中给邮件一个正确的发件人地址,例如,

return $this->markdown('emails.contact.contact-form')->from('example@test.in', 'Example');

或者你也可以在 .env 中配置它,比如,

MAIL_FROM_ADDRESS=example@test.in
MAIL_FROM_NAME=Example

关于php - 拉维尔 6 : Cannot send message without a sender address,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61072923/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com