我正在尝试使用laravel从网页发送消息。
下面是我的表格App/Mail/contact.php
:
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Queue\SerializesModels;
class contact extends Mailable
{
use Queueable, SerializesModels;
public $details;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct($details)
{
//
$this->details=$details;
}
/**
* Get the message envelope.
*
* @return \Illuminate\Mail\Mailables\Envelope
*/
public function envelope()
{
return new Envelope(
subject: 'Contact',
);
}
/**
* Get the message content definition.
*
* @return \Illuminate\Mail\Mailables\Content
*/
public function content()
{
return new Content(
view: 'emails.contact',
);
}
/**
* Get the attachments for the message.
*
* @return array
*/
public function attachments()
{
return [];
}
}
MailSenderController
:
namespace App\Http\Controllers;
use Illuminate\Http\Request;
//use redirect
use Illuminate\Support\Facades\Redirect;
//import mail support
use Illuminate\Support\Facades\Mail;
//import mailsender
use App\Mail\contact;
use Session;
class MailSenderController extends Controller
{
//
function sendMail(Request $request){
//Validate Here
$request->validate([
'name'=>'required',
'email'=>'required',
'message'=>'required'
]);
//Collect Posted data;
$details=[
'name'=>$request->name,
'email'=>$request->email,
'subject'=>'Testing Variable',
'message'=>$request->message,
];
//send mail
Mail::to('mymail@gmail.com')->send(new contact($details));
//redirect to contact with success message
return redirect(url()->previous() .'#form5-d')
->with("message","Message sent");
}
}
这是我的联系人视图的主体
<body>
<h1 class="text-primary">Thank's for reaching out to me!</h1>
<p>
<br>
Hello,
<br>
{{ $details->name }} just sent you a message from your Portfolio website<br>
<br>
<h3>From</h3>{{$name }}
<h3>Subject</h3>{{$details['subject']}}
<br>
<h3>Email</h3> {{$details['email']}}
<br>
<h3>Message</h3>
{{$details['message']}} <br>
</body>
邮件被送到了电子邮件地址,但在我的邮件中,我得到了
{{ $details-〉name }}刚刚从您的投资组合网站向您发送了一条消息
从
{{$姓名}}
主题
{{$详细信息['主题']}}
电子邮件
{{$详细信息['电子邮件']}}
信息
{{$详细信息['消息']}}
1条答案
按热度按时间62lalag41#
您需要在App/Mail/contact.php的方法附件中返回$details