php


send mail in laravel 5.4 with request input


I have a contact form with fields like name, email, phone, etc. I want to pass the fields into the email sent and the example i tried below doesnt seem to send the variables to the html email thats being sent out.
this is in the Route::post of this page:
$data = [
'name' => $request->input('name'),
'email' => $request->input('email'),
'phone' => $request->input('phone'),
'message' => $request->input('message')
];
Mail::to('info#getkutt.com')->send(new ContactForm($data));
then in the contactform.php under the mail folder within the build method i have
public function build()
{
return $this->from('no-reply#domain.com')->view('emails.app.contact-form-submission');
}
Create public properties in your ContactForm mailabel class and receive data from controller to that class using constuctor.
For example-
public $name;
public function __construct($data)
{
$this->name= $data.name;
}
Here an example from the laravel docs
namespace App\Mail;
use App\Order;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
class YOURCLASSNAME extends Mailable
{
use Queueable, SerializesModels;
//Here you are going to define the variables
//which you are pass to your view
public $name;
public $email;
public $phone;
public $message;
/**
* Create a new message instance.
*
* #return void
*/
public function __construct(Order $order)
{
//Now in the construct, you receive the input from request
$this->name = $request->input('name');
$this->email = $request->input('email');
$this->phone = $request->input('phone');
$this->message = $request->input('message');
}
/**
* Build the message.
*
* #return $this
*/
public function build()
{
//And now you return the input to your view
return $this->view('emails.app.contact-form-submission')
->with([
'name' => $this->name,
'email' => $this->email,
'phone' => $this->phone,
'message' => $this->message,
]);
}
}
After that, you can use any variable of the with in your blade
The name: {{ $name }} and email: {{ $email }}

Related Links

Loop row in bootstrap every 3 columns
Get friends name/id list form graph api into array
LAMP shows index.php in var/www/html instead of project
How To play 25MB+ audio file directly from google drive in HTML 5?
PHP/MYSQL - Select option value not being sent?
Laravel : How to use a parameters in a Form POST to be use in a Route::post?
How to convert object format to json format in php
laravel,how i can change the code to return an array?
How to make At Least Two Field Required to fill in Laravel 5.2
How do I allow PHP to run when the script is not in the URL?
How to check if a file is BEING used, i.e. some command is being executed on the data in that file?
Display profile data from database when login
How to integrate laravel packages into an application
Log into a Django project using Magento user database SSO
Image not show in recyclerview from server
php table exporting it to excel [duplicate]

Categories

HOME
xcode
facebook-messenger
initialization
visual-studio-2010
semantic-web
repair
ag-grid
onvif
tweepy
tfs2010
port
heuristics
tiff
sql-injection
spam
deepfreeze
adobe-illustrator
pfobject
raml
altium-designer
connection-refused
rxjs5
intel
channel
substring
backendless
tracing
clipboard
laravel-4.2
boolean-logic
source-insight
vcenter
lxml
cloudera-manager
bootstrap-sass
autoencoder
google-now
spring-restcontroller
pyttsx
moinmoin
xcode8.2
image-registration
hibernate-ogm
android-webservice
watir-webdriver
android-mediarecorder
deedle
ptvs
email-forwarding
dblink
emacs25
polymaps
prefetch
rational-performance-test
carmen
openseadragon
qtcpsocket
dojo-build
deferred-rendering
adp
strpos
jeditable
gridbaglayout
i2b2
cortana
boost-proto
godeps
stack-smash
unhandled
karma-coverage
whitespace-language
dos2unix
iodocs
libgcc
category-theory
stripe.net
commenting
proxy-server
spring-security-acl
smips
ax
dynamic-rdlc-generation
dibs
cmath
cyrillic
red-system
handshake
email-verification
user-forums
semantic-merge
towers-of-hanoi
clrprofiler
chronometer
platform-independent
motodev-studio
groovy-console
data-dump
kernel32
directshow.net
digiflow
servlet-container
raw-data
aspbutton
rawcontacts
bucket
ning
activex-exe
webclient.uploaddata

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App