Once you send the mail to the queue you don't have access to the session variables: Ie input::get. You passed in the $data array? You have to reference that variable $data['name'] Etc
Sep 7, 2015
56
Level 2
Queue is stripping out data
I have a contact form that sends me an email after someone fills it out. Everything worked great, until i put the contact form in a queue. Now the email comes to me without the user's data, This is the controller:
public function getContactUsForm(){
//Get all the data and store it inside Store Variable
$data = Input::all();
//Validation rules
$rules = array (
'name' => 'required',
'email' => 'required|email',
'subject' => 'required',
'msg' => 'required',
);
//Validate data
$validator = Validator::make ($data, $rules);
//If everything is correct then run passes.
if ($validator -> passes()){
//Send email using Laravel send function
Mail::Queue('enquiry', $data, function($msg) use ($data)
{
$msg->to('my@email.com', 'Enquiry')->subject('contact request');
});
return Redirect::to('/')->with(array('note' => 'Thank you! Your message has been recieved.', 'note_type' => 'success') );
}else{
//return contact form with errors
return Redirect::to('/contact')->withErrors($validator);
}
}
}
This is the enquire.blade.php file:
<!--This is a blade template that goes in email message to site administrator-->
<?php
//get the first name
$name = Input::get ('name');
$email = Input::get ('email');
$subject = Input::get ('subject');
$msg = Input::get ('msg');
$date_time = date("F j, Y, g:i a");
$userIpAddress = Request::getClientIp();
?>
<h1>We been contacted by.... </h1>
<p>
Name: <?php echo ($name); ?> <br>
Email address: <?php echo ($email);?> <br>
Subject: <?php echo ($subject); ?><br>
Message: <?php echo ($msg);?><br>
Date: <?php echo($date_time);?><br>
User IP address: <?php echo($userIpAddress);?><br>
</p>
This the email that comes to my inbox:
We been contacted by....
Name:
Email address:
Subject:
Message:
Date: September 8, 2015, 2:59 am
User IP address: 127.0.0.1
Is there something wrong with the code that the queue removes the $data?
Please or to participate in this conversation.