laravel-4.2


Undefine variable via post method in sending email from array using laravel 4.2


I was trying to get my data from my form and sending it to an email address. The problem is my variable got undefined. I'm using laravel4.2 in my current project.
This is my form screenshot:
This is the error information:-
This in my form code:
<form method="post" action="{{URL::route('store_mail_contact')}}">
<div class="row">
<div class="col-lg-6 col-md-6 col-sm-12">
<div class="form-group{{ ($errors->has('name')) ? ' has-error' : ''}}">
<label>Name:</label>
<input class="form-control" value="{{Input::old('name')}}" type="text" name="name" placeholder="Enter name...">
</div>
</div>
<div class="col-lg-6 col-md-6 col-sm-12">
<div class="form-group{{ ($errors->has('email')) ? ' has-error' : ''}}">
<label>Email:</label>
<input class="form-control" value="{{Input::old('email')}}" type="email" name="email" placeholder="Enter email...">
</div>
</div>
</div>
<div class="row">
<div class="col-lg-6 col-md-6 col-sm-12">
<div class="form-group{{ ($errors->has('postcode')) ? ' has-error' : ''}}">
<label>Postcode:</label>
<input class="form-control" value="{{Input::old('postcode')}}" type="text" name="postcode" placeholder="Enter postcode...">
</div>
</div>
<div class="col-lg-6 col-md-6 col-sm-12">
<div class="form-group{{ ($errors->has('country')) ? ' has-error' : ''}}">
<label>Country:</label>
<select class="form-control" name="country">
<option value="" selected="selected">Select Country</option>
#foreach( AIA::all() as $aia)
<option value="{{ $aia->country }}">{{ $aia->country }}</option>
#endforeach
</select>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group{{ ($errors->has('subject')) ? ' has-error' : ''}}">
<label>Subject:</label>
<input class="form-control" value="{{Input::old('subject')}}" type="text" name="subject" placeholder="Enter subject...">
</div>
<div class="form-group{{ ($errors->has('messages')) ? ' has-error' : ''}}">
<label>Messages:</label>
<textarea class="form-control" name="messages">{{Input::old('message')}}</textarea>
</div>
</div>
</div>
{{Form::token()}}
<div class="form-group">
<button type="submit" value ="submit" name="submit" class="btn btn-primary">SUBMIT</button>
<button type="reset" value ="reset" name="reset" class="btn btn-primary">RESET</button>
</div>
</form>
This is my post controller:
public function postContact(){
$validate = Validator::make(Input::all(),array(
'name'=>'required',
'email'=>'required',
'subject'=>'required',
'country'=>'required',
'postcode'=>'required'
));
if ($validate->fails()) {
return Redirect::route('mail_contact')->withErrors($validate)->withInput();
}else{
$mailsending ="likdy2015#gmail.com";
$name = Input::get('name');
$subject = Input::get('subject');
$postcode = Input::get('postcode');
$country = Input::get('country');
$email = Input::get('email');
$messages= Input::get('messages');
$data = array(
'email_sending'=>$mailsending,
'name'=>$name,
'subject'=>$subject,
'postcode'=>$postcode,
'country'=>$country,
'email'=>$email,
'messages'=>$messages
);
$mail = Mail::send('emails.message', $data, function($message) use ($mailsending,$name)
{
$message->to($mailsending, $name)->subject($subject);
});
if($mail->send()){
return Redirect::route('mail_contact')->with('success','Your account has been created. We have sent you an email to active your account!');
}else{
return Redirect::route('mail_contact')
->with('fail','Mail sent not success!');
}
}
}
This is my routes:
Route::group(array('before'=>'csrf'),function(){
Route::post('contact',array('as'=>'store_mail_contact','uses'=>'HomeController#postContact'));
});
I think the error is because the $subject is not seen in the current context, I mean you don't passed it to the callback.
Try passing it through use().
I have a working example here:
$GLOBALS['email'] = $email;
$GLOBALS['subject'] = $subject;
Mail::send('folder.myview', array("key" => $value_passed_to_view), function($message) {
$message->to($GLOBALS['email'])
->subject($GLOBALS['subject']);
});
unset($GLOBALS['email']);
unset($GLOBALS['subject']);
Find more information here

Related Links

Itunes api call limit
how to solve update part error in laravel 4.2
How to delete a directory with its file from the public storage in laravel 4.2
Laravel 4.2 site doesn't work on localhost
send value from views in form of {{ FORM:: }} and recieve value in controller
how to count column(with data) number in laravel excel maatwebsite
Where to write common function or logic in laravel 4.2
post ajax jquery laravel 4 error 500
Undefine variable via post method in sending email from array using laravel 4.2
IronQueue sending jobs twice
Upload Log files to different server : Laravel
Url loading the login page again after login in Laravel4

Categories

HOME
spring-data
freeradius
yahoo-weather-api
paypal-ipn
exchange-server
softlayer
add-on
subdomain
visual-studio-2010
cryptography
qooxdoo
flurry
apache-kafka-connect
openfoam
impala
anchor
gtk
swarm
angular4
powermock
max-msp-jitter
exe
word2vec
checkout
bazaar
parceler
adminlte
jest
angular2-highcharts
unity-container
hdl
sharedpreferences
restier
tracing
hdmi
clipboard
tortoisehg
sales
dotcms
infopath2010
reporting
listjs
spring-rabbitmq
express-session
djcelery
python-sounddevice
pyttsx
elasticsearch-aggregation
expandablelistview
md5-file
datediff
pen
sidewaffle
researchkit
e
livecycle
always-on-top
swiffy
utf-16
psd
ioexception
python-cffi
linuxbrew
http.client
ambiguity
sqlbase
compositetype
cache-manifest
flow-js
shoes
scala-swing
mod-auth-openidc
nhibernate-criteria
string.format
device-admin
jquery-mobile-flipswitch
senchatouch-2.4
forceclose
sqlbindparameter
mft
strcmp
saga
coalesce
hints
dojo-1.9
xalan
cgrectmake
daap
getproperty
jdom
monocross
flymake
server-variables
getopts
office-automation
kernel32
rtd
ognl
oracle-pro-c
fxruby
inversion
tso
community-server
account-management

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