Undefined variable: toemail Laravel mail issue - laravel

I am going to send mail using laravel
so i have
$mailD = DB::table('users')->select('name','email')->where('id', $request->input('Appraiserid'))->get();
$toemail = $mailD[0]->email;
When i echo $toemail it will echo value.
And when i send mails
if ($update) {
$datamail = [
'title' => $getcycle[0]->Heading,
'Heading' => 'Form Reject',
'Name' => $mailD[0]->name,
'email' => $mailD[0]->email
];
Mail::send('voyager::users.send', ["data1" => $datamail], function ($message) {
$message->subject('Form reject');
$message->from('test#gmail.com');
$message->to($toemail);
});
}
Got an error like
ErrorException in Users.php line 631: Undefined variable: toemail
Any help would be appreciated.

try this code for more see
Mail::send('voyager::users.send', ["data1"=>$datamail], function ($message) use ($toemail) {
$message->subject('Form reject');
$message->from('test#gmail.com');
$message->to($toemail);
});

Related

Laravel How to solve Swift Message attach Data error?

$pdf = Pdf::loadHTML($html);
Mail::send(array(), array(), function ($message) use ($fullname, $email, $html, $pdf) {
$message->to([$email => $fullname])
->subject('New Test Mail')
->from('noreply#siteaddress.com', 'Test Mail')
->setBody($html, 'text/html')
->attachData($pdf->output(), "text.pdf");
});
I'm doing the above sending email, but I'm getting an error. I tried all the ways but couldn't find a solution. What could be the cause of this problem?
Error Message:
Call to undefined method Swift_Message::attachData()
Just swap setBody method with attachData like this:
$pdf = Pdf::loadHTML($html);
Mail::send(array(), array(), function ($message) use ($fullname, $email, $html, $pdf) {
$message->to([$email => $fullname])
->subject('New Test Mail')
->from('noreply#siteaddress.com', 'Test Mail')
->attachData($pdf->output(), "text.pdf")
->setBody($html, 'text/html');
});
It worked for me.

fail to update data into database

Controller
function edit($RegNo){
$data['row'] = $this->ManageTrenter code hereansfers->GetById($RegNo);
$this->load->view('admin/transferupdate', $data);
}
enter code here
public function update($RegNo){
$this->ManageT`enter code here`ransfers->update($RegNo);
redirect('admin/ManageTransfer/transfer');
}
Model
function GetById($RegNo){
return $this->db->get_where('user_transfer', array('RegNo' => $RegNo ))->row();
}
function update($RegNo){
$arr['School'] = $this->input->post('School');
$arr['Date'] = $this->input->post('Date');
$arr['RegNo'] = $this->input->post('RegNo');
$arr['Class'] = $this->input->post('Class');
$arr['New'] = $this->input->post('New');
$arr['Reason'] = $this->input->post('Reason');
$arr['UserId'] = $this->input->post('UserId');
$arr['Status'] = $this->input->post('Status');
$this->db->where(array('RegNo' => $RegNo));
$this->db->update('user_transfer', $arr);
}
View
RegNo);?>">
error occur
A PHP Error was encountered
Severity: Notice
Message: Trying to get property of non-object
Filename: admin/transferupdate.php
Line Number: 12
replace
$this->db->where(array('RegNo' => $RegNo));
like this
$this->db->where('RegNo', $RegNo);
function update($RegNo){
$arr= array();
$post_data=$this->input->post();
$arr=(
'School' => $post_data['School'],
'Date' => $post_data['Date'],
'RegNo' => $post_data['RegNo'],
'Class' => $post_data['Class'],
'New' => $post_data['New'],
'Reason' => $post_data['Reason'],
'UserId' => $post_data['UserId'],
'Status' => $post_data['Status']
);
$this->db->where('RegNo', $RegNo);
$this->db->update('user_transfer', $arr);
}

Laravel 7- "Undefined index: email", when trying to send email

I am trying to send email using Laravel, but I am getting the error message
"Undefined index: email"
Here is my code
public function contact_us(Request $request){
$cu_full_name = $request->cu_full_name;
$cu_email = $request->cu_email;
$cu_message = $request->cu_message;
date_default_timezone_set("Asia/Kolkata");
$cu_received_dt = date("Y-m-d,H:i:s ");
$data= array([
'name'=>$cu_full_name,
'email'=> $cu_email,
'message'=>$cu_message
]);
Mail::send('emails.home',$data,function ($message) use($data){
$message->from('example#example.com');
$message->to($data['email'])->subject('New Message Received.'); **<-error message for this line**
});
//Other codes
Why are you wrapping array inside array ?
try to define data like that :
$data= [
'name'=>$cu_full_name,
'email'=> $cu_email,
'message'=>$cu_message
];
Or,
$data= array(
'name'=> $cu_full_name,
'email'=> $cu_email,
'message'=> $cu_message
);

Laravel - sending recovery mail

I'm trying to send a recovery mail using Laravel. I have the following recovery method:
public function recovery(Request $request)
{
$validator = Validator::make($request->only('email'), [
'email' => 'required'
]);
if($validator->fails()) {
throw new ValidationHttpException($validator->errors()->all());
}
$response = Password::sendResetLink($request->only('email'), function (Message $message) {
$message->subject(Config::get('boilerplate.recovery_email_subject'));
});
switch ($response) {
case Password::RESET_LINK_SENT:
return $this->response->noContent();
case Password::INVALID_USER:
return $this->response->errorNotFound();
}
}
I tried to output $request->email and the reset email is the output, but for some reasons I get the following error:
Undefined index: email
at
"/home/pokemoti/public_html/api/vendor/laravel/framework/src/Illuminate/Auth/Passwords/PasswordBrokerManager.php" on line 74
Any idea what could have gone wrong?
Fixed it by adding the following line in my config/auth.php passwords->users array:
'email' => 'auth.emails.password',
took it from another project where it worked.

laravel5.2 Mailgun work but not send the email

Hello I setup mailgun correctly. and did form contact us.
To send the message to my email by this code
public function send_contact_us()
{
$data = array(
'name' => Request::get('name'),'email'=>Request::get('email'),'subject'=> Request::get('subject'));
$client_m=Request::get('message');
$data_message=array('message_c'=>$client_m);
echo "we above MAIL";
Mail::send('emails.message',$data_message, function ($message)use ($data) {
$message->from($data['email'], 'E-SHOPPER');
$message->to("azharnabil013#yahoo.com")->subject($data['subject']);
});
return view('contact_us', array('title' => 'Welcome', 'description' => '', 'page' => 'contact_us','subscribe'=>'','sent'=>"Message has been sent successfuly"));
}
The code run correctly and this page display
But when I check my email I didn't find any message
I don't know why this problem .please, anyone help me.

Resources