Undefined variable: pdf_show whenever I try to send mail with $pdf_show attachment.
$pdf = View::make('site.bill', compact('invoice_bill'))->render();
$pdf_show = PDF::load($pdf, 'A4', 'portrait')->output();
$msg = Config::get('ashram.delivered');
Mail::send('blank', array('msg' => Config::get('ashram.delivered'),'id'=>$id,'is_approve'=>$is_approve), function($message){
$message->to(Request::segment(3), Input::get('name'))->cc('subhankarbhattacharjee56#yahoo.in')->subject('Delivery')//;
->attach($pdf_show , "Tax Invoice");
});
Try adding use($pdf_show) to your mail function
$pdf = View::make('site.bill', compact('invoice_bill'))->render();
$pdf_show = PDF::load($pdf, 'A4', 'portrait')->output();
$msg = Config::get('ashram.delivered');
Mail::send('blank', array('msg' => Config::get('ashram.delivered'),'id'=>$id,'is_approve'=>$is_approve), function($message) use ($pdf_show) {
$message->to(Request::segment(3), Input::get('name'))->cc('subhankarbhattacharjee56#yahoo.in')->subject('Delivery')
->attachData($pdf_show , "Tax Invoice");
});
Related
$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.
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);
});
i try to send email in laravel 5.2 and its works.
my problem is how to convert a view with its data to PDF then attach it to email
i try this
$datastd['fname']=$printqu->std_fname;
$datastd['mname']=$printqu->std_mname;
$datastd['lname']=$printqu->std_lname;
$datastd['email']=$printqu->std_email;
$datastd['email']=$printqu->std_email;
$datastd['orgname']=$printqu->name;
$datastd['depname']=$printqu->Dep_Name;
Mail::send('email.train_form',['datastd'=>$datastd], function($mail) use ($datastd){
$mail->to($datastd['email'],$datastd['fname'],$datastd['mname'],$datastd['lname'],$datastd['orgname'],$datastd['depname'])->attachData($datastd, 'printPreviewm.pdf')->from('everyone#gmail.com')->subject('Training Forms');
});
the error is time out
please i need your help in this
Edit: Sorry, your question is based on Laravel 5.2 and my answer is based on Laravel 5.4. As of generating a PDF can still be done with the DOMPDF package, and the docs for attaching it to a mail can be found in the official Laravel docs here
Generating a PDF based on a view template can be easily done by using a package such as DOMPDF made by Barryvdh
Generating a PDF would look something like this
$view = View::make('any.view', compact('variable'));
$contents = $view->render();
$pdf = App::make('dompdf.wrapper');
$pdf->loadHTML($contents);
$output = $pdf->output();
Storage::put('/folder/your-file.pdf', $output);
Attaching a document to a mail is pretty simple in Laravel (5.4) [docs]
// file location
$file = storage_path('app/folder/your-file.pdf');
// return mail with an attachment
return $this->view('emails.confirm')
->from('me#stackoverflow.com', 'From')->subject('New mail')
->with([
'name' => $this->data['name'],
])->attach($file, [
'as' => 'File name',
'mime' => 'application/pdf',
]);
i try the following
$view = View::make('printPreview', compact('printqu','printqu2'));
$contents = $view->render();
$pdf = App::make('dompdf.wrapper');
$pdf->loadHTML($contents);
$output = $pdf->output();
Storage::put('app/folderletter/your-file.pdf', $output);
$datastd['fname']=$printqu->std_fname;
$datastd['mname']=$printqu->std_mname;
$datastd['lname']=$printqu->std_lname;
$datastd['email']=$printqu->std_email;
$datastd['email']=$printqu->std_email;
$datastd['orgname']=$printqu->name;
$datastd['depname']=$printqu->Dep_Name;
$file = storage_path('app/folderletter/your-file.pdf');
Mail::send('email.train_form',['datastd'=>$datastd], function($mail) use ($datastd,$file){
//$pdf = PDF::loadView('printPreviewm',['datastd'=>$datastd]);
$mail->to($datastd['email'],$datastd['fname'],$datastd['mname'],$datastd['lname'],$datastd['orgname'],$datastd['depname'])
->from('everyone#gmail.com')->subject('Training Forms')
->attach('app/folderletter/your-file.pdf', [
'as' => 'name.pdf',
'mime' => 'application/pdf',
]);
});
i saves the document in Storeag
but also the same
time out!!!!
so the message not sent.
thanks all of you.. i solve it. it was something like this
$view = View::make('printPreview', compact('printqu','printqu2'));
$contents = $view->render();
$pdf = App::make('dompdf.wrapper');
$pdf->loadHTML($contents);
$output = $pdf->output();
Storage::put('app/folderletter/your-file.pdf', $output);
$datastd['fname']=$printqu->std_fname;
$datastd['mname']=$printqu->std_mname;
$datastd['lname']=$printqu->std_lname;
$datastd['email']=$printqu->std_email;
$datastd['email']=$printqu->std_email;
$datastd['orgname']=$printqu->name;
$datastd['depname']=$printqu->Dep_Name;
//$file= public_path(). "/app/".$sestest3->dep_path;
$file = storage_path(). "/app/app/folderletter/your-file.pdf";
Mail::send('email.train_form',['datastd'=>$datastd], function($mail) use ($datastd,$file){
//$pdf = PDF::loadView('printPreviewm',['datastd'=>$datastd]);
$mail->to($datastd['email'],$datastd['fname'],$datastd['mname'],$datastd['lname'],$datastd['orgname'],$datastd['depname'])
->from('everyone#gmail.com')->subject('Training Forms')
->attach($file, [
'as' => 'name.pdf',
'mime' => 'application/pdf',
]);
});
i have one requirement from in my application..so when ever user insert details in the requirement.and then submit..the mail will go to the particular vendor with one link..when vendor click on the link i redirect the page to login page..
So what i want to do is i want to send email link with last inserted id..
Here is my controller:
public function requirement()
{
$data["msg"]="";
$this->load->model('RequirementModel');
$data['user']=$this->RequirementModel->getusers();
$data['rolename']=$this->RequirementModel->getrolename();
if($this->input->post())
{
$this->RequirementModel->add_requirement($this->input->post());
$all_users = $this->input->post('user_id');
foreach($all_users as $key)
{
$get_email = $this->RequirementModel->get_user_email_by_id($key);
$req_id = $this->input->post('req_id');
$role_name = $this->input->post('role_name');
$vacancies = $this->input->post('vacancies');
$experience = $this->input->post('experience');
$jd = $this->input->post('jd');
$hiring_contact_name = $this->input->post('hiring_contact_name');
$hiring_contact_number = $this->input->post('hiring_contact_number');
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://md-in-42.webhostbox.net',
'smtp_port' => 465,
'smtp_user' => 'test3#clozloop.com',
'smtp_pass' => 'test3'
);
$this->load->library('email',$config);
$this->email->set_mailtype("html");
$this->email->from('test3#clozloop.com', 'bharathi');
$this->email->to($get_email);
$this->email->subject('this is our requirements pls go through it');
$link = 'Click on this link - <a href="http://localhost/job_portal/index.php/Login/signin>Click Here</a>';
$this->email->message($link);
print_r($get_email);
if($this->email->send())
{
echo "email sent";
}
else
{
echo "email failed";
}
}
}
$this->load->view('Requirements/requirements',$data);
}
Can anyone help me..
Thanks in advance..
What you need is the database helper function insert_id(), it returns the id of the last insert: https://www.codeigniter.com/userguide3/database/helpers.html?highlight=insert_id
Have your add_requirement function of the RequirementModel model return the insert_id like so:
return $this->db->insert_id();
Then just save that value when you call the function:
$insert_id = $this->RequirementModel->add_requirement($this->input->post());
I want to send an email to user from my application with the content of the email loaded from a view . This is the code i've tried out till now:
$toemail = "user#email.id";
$subject = "Mail Subject is here";
$mesg = $this->load->view('template/email');
$this->load->library('email');
$config['charset'] = 'utf-8';
$config['wordwrap'] = TRUE;
$config['mailtype'] = 'html';
$this->email->initialize($config);
$this->email->to($toemail);
$this->email->from($fromemail, "Title");
$this->email->subject($subject);
$this->email->message($mesg);
$mail = $this->email->send();
You need to call $this->load->library('email'); within the controller as well for the email in CI to work.
Also , in your code : $fromemail is not initialized.
You need to have SMTP support on your server.
$config should be declared as an array before assigning values and keys.
Working Code:
$this->load->library('email');
$fromemail="ad#c.com";
$toemail = "user#email.id";
$subject = "Mail Subject is here";
$data=array();
// $mesg = $this->load->view('template/email',$data,true);
// or
$mesg = $this->load->view('template/email','',true);
$config=array(
'charset'=>'utf-8',
'wordwrap'=> TRUE,
'mailtype' => 'html'
);
$this->email->initialize($config);
$this->email->to($toemail);
$this->email->from($fromemail, "Title");
$this->email->subject($subject);
$this->email->message($mesg);
$mail = $this->email->send();
Edit:
$mesg = $this->load->view('template/email',true); should be having the true as pointed out by lycanian. By setting it as true , it doesn't send data to the output stream but it will return as a string.
Edit:
$this->load->view(); need a second parameter with data or empty like $mesg = $this->load->view(view,data,true);, if not it wont work
This line $mesg = $this->load->view('template/email',true); should be like this
$mesg = $this->load->view('template/email','',true);
with the single quotes before the value true, and it will work perfectly
Email template send In codeigniter we need to put and meta tag before sending email
$this->data['data'] = $data;
$message = $this->load->view('emailer/create-account', $this->data, TRUE);
$this->email->set_header('MIME-Version', '1.0; charset=utf-8');
$this->email->set_header('Content-type', 'text/html');
$this->email->from($email, $name);
$this->email->to('emailaddres#mail.com');
$this->email->subject($subject);
$this->email->message($message);
$this->email->send();
U will try it!! it's working for mine after many errors facing
$subject = 'New message.';
$config = Array(
'protocol' => 'sendmail',
'smtp_host' => 'Your smtp host',
'smtp_port' => 465,
'smtp_user' => 'webmail',
'smtp_pass' => 'webmail pass',
'smtp_timeout' => '4',
'mailtype' => 'html',
'charset' => 'utf-8',
'wordwrap' => TRUE
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->set_header('MIME-Version', '1.0; charset=utf-8');
$this->email->set_header('Content-type', 'text/html');
$this->email->from('from mail address', 'Company name ');
$data = array(
'message'=> $this->input->post('message')
);
$this->email->to($toEmail);
$this->email->subject($subject);
$body = $this->load->view('email/sendmail.php',$data,TRUE);
$this->email->message($body);
$this->email->send();