I am using phpword package in my laravel. I edit content and try to send file as email attachment but email attachment docx file not opens it comes with corrupted file in the attachment. please check below code.
below is my code where i am returning the docx file using phpword
$save_path = $storage_path.'output.docx';
$templateProcessor->saveAs($save_path);
$headers = ['Content-Type' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'];
return $WordContent = response()->download($save_path,null,$headers);
below is code which I use to send email
$message->subject($email_data['title'])
->from($email_data['from_email'], $email_data['from'])
->attachData($WordContent, $email_data['title'].'.'.$extension,'mime'=>$mime]);
});
Related
I'm generating pdf using following code in Laravel but the issue is sometimes data is saved in the database and pdf is not generated when i check the pdf folder there is no pdf files with that name, this does not happens every time i generate the pdf but there are some entries in my database for which the pdf is not generated, i want some way so that i can check whether the pdf has been generated and mark status true in the database if pdf is generated later on recreate pdf and send it to user through cron jobs or is there any other way also, Please suggest some solution Thanks
use PDF;
..
..
$DataStore->user_id = $user_id;
$DataStore->description = $description;
$DataStore->save();
if($DataStore) {
$pdf = PDF::loadView('/admin/user_submission_pdf', ['data' => $DataStore]);
$content = $pdf->download()->getOriginalContent();
Storage::put('public/pdfFiles/' . $DataStore->Id . '.pdf', $content);
to download your pdf, change the the line
$content = $pdf->download()->getOriginalContent();
to
$content = $pdf->download('file-name-you-want.pdf');
then at last line should return:
return $content;
I'm posting a CSV file from one Laravel app to another:
Sending:
$contents = file_get_contents($filePath);
Log::debug('contents', ['contents'=>$contents]); // I can see contents of file
Http::withToken($token)->attach('attachment', $contents)->post($uri);
Receiving:
$content = $request->getContent();
Log::debug('about to store content to file...', ['content'=>$content]);
// about to store content to file... {"content":""}
What am I missing here?
Files are not the content, you should fetch the file out with.
$request->file('attachment');
If you want to send a file as a raw request body, this snippet shows you how from the documentation.
$response = Http::withBody(
file_get_contents($filePath), 'text'
)->post($uri);
I have created a pdf file of the bill that the customer can download. What i want to do is save the same pdf in my database without having to download it first and then upload again. Is there a way to do this?
Controller:
public function export(){
$user = Auth::user()['id'];
$now = Carbon::now()->format('Y-m-d');
$wherecond = " userid=".$user." and created_at like '%".$now."%' ";
$bill = DB::table('cartitems')->select('cartid','category','menu','price','created_at')->whereRaw($wherecond)->orderBy('created_at', 'ASC')->get();
$whereconditn = " userid=".$user." and created_at like '%".$now."%' ";
$cost = DB::table('cartitems')->whereRaw($whereconditn)->sum('price');
$pdf = PDF::loadView('/pages.bill', ['bill' => $bill, 'cost' => $cost]);
return $pdf->stream('bill.pdf');
}
Here i have created a pdf on blade bill.blade.php and the user can download the file but can i save the same pdf directly to the database without downloading it for admin part?
You can add BLOB type in your database to save PDF. But it's not the best practice due to the amount of storage that is required.
I suggest you the following process :
Step 1) generate your PDF file
Step 2) save your PDF file on your webserver
Step 3) create a link (URL) to your PDF file
Step 4) save link (URL) in your database
I'm trying to send a calendar invitation in Laravel using spatie/calendar-links package but, in outlook, I get an attachment named "not supported calendar message.ics".
Here's how I generate the file contents and save it in a folder:
$ics = Link::create('Viaggio', $from, $to)
->description('Viaggio Da '.$data['travel']['departure'].', A '.$data['travel']['destination'])
->address($data['travel']['departure']);
\Storage::disk('uploads')->put('invitation.ics', $ics->ics());
$data['ics'] = $ics->ics();
Then i send the email like this:
Mail::send('view.email', $data, function ($message) use ($data) {
$message->from('email#email.coom', 'blablabla');
$message->subject('blablabla');
$message->attachData($data['ics'], 'uploads/invitation.ics', [
'mime' => 'text/calendar;charset=UTF-8;method=REQUEST',
]);
$message->to($data['driver']['notifymail'], $data['driver']['businessname']);
});
Contents of the .ics file:
data:text/calendar;charset=utf8,BEGIN:VCALENDAR%0d%0aVERSION:2.0%0d%0aBEGIN:VEVENT%0d%0aUID:ea22b2a397b12a7b2f629720cd46d84e%0d%0aSUMMARY:Viaggio%0d%0aDTSTART;TZID=UTC:20190323T102643%0d%0aDTEND;TZID=UTC:20190323T122643%0d%0aDESCRIPTION:Viaggio Da mxp\, A Via rossi 13\, Milano%0d%0aLOCATION:mxp%0d%0aEND:VEVENT%0d%0aEND:VCALENDAR
The email itself is fine, the only problem is the ics file: am i missing something? Am i not using the package the right way?
I Need to create an email template. Also I need to load that customer template into another .phtml file and edit before send the email. After editing only I need to send the email. Can anyone please help me how to do this?
I searched and tried for this, but I only found articles related to send email without editing the existing email template.
example: http://www.caritorsolutions.com/blog/158-send-email-from-custom-module-in-magento
You can create an email template when going to System > Transactional Emails. The name you put in is the unique identifier for that template.
<?php
$templateName = 'template_name_you_put_in_in_the_backend';
$to = 'johndoe#example.com';
$customerName = 'John Doe';
// Load our template by template_id
$emailTemplate = Mage::getModel('core/email_template')->loadDefault($templateId);
$vars = array(
'customer_name' => $customerName
// Other vars that can be used in the mplate
);
// Store sends it
$senderName = Mage::getStoreConfig(Mage_Core_Model_Store::XML_PATH_STORE_STORE_NAME);
$senderEmail = Mage::getStoreConfig('trans_email/ident_general/email');
$emailTemplate->setSenderName($senderName);
$emailTemplate->setSenderEmail($senderEmail);
//Send the email!
$emailTemplate->send($to, $customerName, $emailTemplateVariables);
You can of course edit this file through System > Transactional Emails. If this isn't what you mean, can you clarify what you mean by 'editing the existing email template' ?