Step 1. Create mail
php artisan make:mail Contact Mail
<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
class ContactMail extends Mailable
{
use Queueable, SerializesModels;
public $details;
public function __construct($details)
{
$this->details = $details;
}
public function build()
{
return $this->view('email');
}
}
Step 2: In the controller file, get the details of the fiels.
use Illuminate\Support\Facades\Mail;
$name = $request->input('name');
$contact_email = $request->input('contact_email');
$subject = $request->input('subject');
$message = $request->input('message');
$receiver = 'rameshyadavjee@gmail.com';
$details = [
'name' => $name,
'contact_email'=> $contact_email,
'subject' => $subject,
'message' => $message,
'receiver' => $receiver
];
Mail::to($receiver)->send(new \App\Mail\ContactMail($details));
// To use below one use App\Mail\NewRegistrationMail;
//Mail::to($receiver)->send(new NewRegistrationMail($details));
Step 3: Create Blade View
resources/views/email.blade.php
<html>
<head>
<title>New Inquiry</title>
</head>
<body>
<strong>Subject</strong> : {{$_REQUEST['subject']}}<br>
<strong>Name</strong> : {{$_REQUEST['name']}}<br>
<strong>Email</strong> : {{$_REQUEST['contact_email']}}<br>
<strong>Message</strong> : {{$_REQUEST['message']}}
</html>
or
<strong>Subject</strong> : {{$details['subject']}}<br>
<strong>Name</strong> : {{$details['name']}}<br>
<strong>Email</strong> : {{$details['contact_email']}}<br>
<strong>Message</strong> : {{$details['message']}}
That's it
No comments:
Post a Comment