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

How to turn dynamic URL into static URL
php request variables assigning $_GEt
How to embed images in a single HTML / PHP file?
dynamically generating images in PHP sometimes isn't working
Trying to validate captcha with javascript before sending to php form validation
Jquery problem with plugin
really weird symbol in php?
Form isn't moving to the other page I specified, please help. A PHP newbie problem
Magento - Change Customer Id and Order ID
Effective compression in AS3 to be transeferred to PHP
How to generate a unique id for different visitors with PHP?
preg_replace easy for a pro
PHP How to include files based on creation date?
Put a function in an XML field
dynamic array key additions
Wordpress: wp_get_attachment_thumb_url

Categories

HOME
xpath
svn
couchdb
initialization
gentelella
apache-kafka-connect
share
circleci
mailmerge
pm2
mpu6050
dma
phonegap-build
pinterest
vertica
office-ui-fabric
salt-cloud
bazaar
backtracking
amazon-sns
channel
sipp
pdf.js
fusetools
ccavenue
docx4j
copy-protection
nic
tightvnc
apptentive
stackpanel
djcelery
recovery
reset
best-buy-api
task-parallel-library
grails-spring-security
spooler
latexml
apache-toree
doctrine-extensions
spongycastle
aws-kinesis-firehose
tinyioc
ol3-google-maps
nusoap
redisson
winston
extjs4.1
maven-jaxb2-plugin
skip-lists
simple-schema
portability
emf-compare
nitrousio
qtextedit
django-testing
mathml
groovyfx
meld
deferred-rendering
frame-grab
as3-api
wif4.5
certificate-authority
diawi
opencyc
nette
http.client
dsa
asp.net-web-api-helppages
auto-generate
wso2ml
embeddedwebserver
darwin
angular-amd
explain
phpredis
scala-swing
sablecc
jolie
cakephp-2.2
relationships
object-code
libgcc
box2dweb
jini
hyperloglog
pageviews
roxy-fileman
jmenubar
acitree
revmob
bcdedit
eager-loading
oscilloscope
chefspec
image-formats
trialware
autosize
fitch-proofs
mmc3
litespeed
groovy-console
filelock
getopts
nosetests
css-friendly
eaccelerator
ninject-interception
activestate
eai
rtti
stretchblt
watchpoint

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App