``
Excuse the English of translator
I am trying to consult emails in parts since there are more than 4000 to process them, I am working with Laravel and phpimap, I have tried everything, I start programming and I do not understand much of this
I practically just opened the connection, my plan is to use jobs to get those emails in the background but, for now I need to get them since I can't find how
public function index()
{
$account= new mailModel();
$cm = new ClientManager($options = []);
$messages= new MessageCollection($perPage = 500, $page = 6, $pageName = 'page');
#$message= new Message();
$client = $cm->make([
'host' => 'mail.spamanalizer.ibx.lat',
'port' => 993,
'encryption' => 'ssl',
'validate_cert' => true,
'username' => '',
'password' => '',
'protocol' => 'imap'
]);
//Connect to the IMAP Server
$client->connect();
$query=new WhereQuery($client);
$folder = $client->getFolderByName('Recibidos');
$query->all()->chunked(function($messages, $chunk){
/** #var \Webklex\PHPIMAP\Support\MessageCollection $messages */
dump("chunk #$chunk");
$messages->each(function($message){
/** #var \Webklex\PHPIMAP\Message $message */
dump($message->uid);
});
}, $chunk_size = 50, $start_chunk = 1);
echo "<pre>".print_r($messages, true)."</pre>";
}
Related
i am new in laravel and use Astrotomic / laravel-translatable package for translation
i have problem when i want to add two langue at same time.
i have name_en,name_ar,discription_an,disriptionar as inputs fields.
i get this error Creating default object from empty value
so how can I solve my problem
this is link of package https://github.com/Astrotomic/laravel-translatable
// start add data
public function store(CategoryRequest $request)
{
// prepare data
$validatedData = array(
'url' => $request->url,
'slug' => $request->slug,
'status' => $request->status,
'last_updated_by' => auth('admin')->user()->id,
'created_by' => auth('admin')->user()->id,
'created' => time(),
);
$translated = array(
'name_en' => $request->name_en,
'name_ar' => $request->name_ar,
'description_en' => $request->description_en,
'description_ar' => $request->description_ar,
);
//start define categoru is sub or main
$request ->sub ==1 ? $validatedData['parent_id'] = $request ->category_id: $validatedData['parent_id']=null;
// start update data
DB::beginTransaction();
$add = Category::create($validatedData);
$id = $add->id;
// strat update category report
$categoryReport = CategoryReport::create(
['status' =>$validatedData['status'],
'category_id' =>$id,
'created_by' =>$validatedData['created_by']
,'last_updated_by' =>$validatedData['last_updated_by']]);
$add->translate('ar')->name = $translated['name_ar'];
$add->translate('en')->name = $translated['name_en'];
$add->translate('ar')->description = $translated['description_ar'];
$add->translate('en')->description =$translated['description_en'];
$add ->save();
DB::commit();
return redirect()->back()->with('success','تم اضافه البيانات بنجاح');
}
I am trying to fetch an email from outlook Inbox with the Imap package of Laravel. it is working fine with Gmail. but when I try to fetch emails from outlook it gives No message error
ImapController.php
*/
public function index()
{
// dd(phpinfo());
// imap_open('{outlook.office365.com:993/imap/ssl/novalidate-cert}INBOX', 'info#coldxpress.com.au', 'Dac67132');
$oClient = Client::account('default');
$oClient->connect();
//Get all Mailboxes
/** #var \Webklex\IMAP\Support\FolderCollection $aFolder */
$aFolder = $oClient->getFolders('INBOX.Sent');
//Loop through every Mailbox
/** #var \Webklex\IMAP\Folder $oFolder */
foreach ($aFolder as $oFolder) {
//Get all Messages of the current Mailbox $oFolder
/** #var \Webklex\IMAP\Support\MessageCollection $aMessage */
$aMessage = $oFolder->messages()->since('10.02.2020')->get();
/** #var \Webklex\IMAP\Message $oMessage */
foreach ($aMessage as $oMessage) {
echo $oMessage->getSubject() . '<br />';
// echo 'Attachments: ' . $oMessage->getAttachments()->count() . '<br />';
// echo $oMessage->getHTMLBody(true);
}
}
// return view('home');
}
Config/imap.php
'accounts' => [
'default' => [// account identifier
'host' => env('IMAP_HOST', 'outlook.office365.com'),
'port' => env('IMAP_PORT', 993),
'protocol' => env('IMAP_PROTOCOL', 'imap'), //might also use imap, [pop3 or nntp (untested)]
'encryption' => env('IMAP_ENCRYPTION', 'ssl'), // Supported: false, 'ssl', 'tls', 'notls', 'starttls'
'validate_cert' => env('IMAP_VALIDATE_CERT', false),
'username' => env('IMAP_USERNAME', 'info#coldxpress.com.au'),
'password' => env('IMAP_PASSWORD', '*********'),
],
I want to fetch Emails from Outlook account.
I am having problems using the getImageSrc and getContentBase64Encoded under the AttachmentMask::class webklex.
The error message shows Method Webklex\IMAP\Message::getImgSrc() is not supported and Method Webklex\IMAP\Message::getContentBase64Encoded () is not supported.
$oClient = new Client([
'host' => $imap['host'],
'port' => $account->imap_port_no,
'encryption' => $ssl,
'validate_cert' => true,
'username' => $account->user_name,
'password' => $account->password,
]);
$oFolder = $oClient->getFolder($folder_name);
$oMessage = $oFolder->getMessage($message_id, null, null, true, true, true);
$test = $oMessage->getImgSrc();
//or this
$test = $oMessage->getContentBase64Encoded();
got it working already using these line of codes.
$attachment_mask = \Webklex\IMAP\Support\Masks\AttachmentMask::class;
$oClient->setDefaultAttachmentMask($attachment_mask);
$attachment = $oMessage->getAttachments()->first();
$masked_attachment = $attachment->mask();
$link = $masked_attachment->getImageSrc()
;
Am getting that error when submitting my form data for storing , Below is my approve_request_post function in controller.
public function approve_request_post(Request $request, $request_hash)
{
$request->validate([
'hosp_no' => 'required',
'transport_cost' => 'required',
'days' => 'required|numeric',
'per_diem' => 'required|numeric',
'service_type' => 'required',
'trans_mean' => 'required',
'cost_payable' => 'required|numeric',
'patient_age' => 'required|numeric',
'doctors_name' => 'required',
'appointment_date' => 'required|date',
'comment' => 'required',
]);
// Start transaction
DB::beginTransaction();
$request = ReferralRequestModel::where('request_hash', $request_hash)->firstOrFail();
$remark = new InsurerRemarksModel;
$remark->ir_hash = encrypt($remark->ir_id);
$remark->req_id = $request->request_id;
$remark->insurer_id = Auth::user()->insurers->insurer_id;
$remark->req_id = $request->request_id;
$remark->hosp_no = $request->input('hosp_no');
$remark->service_type = $request->input('service_type');
$remark->transport_cost = $request->input('transport_cost');
$remark->trans_mean = $request->input('trans_mean');
$remark->days = $request->input('days');
$remark->cost_payable = $request->input('cost_payable');
$remark->patient_age = $request->input('patient_age');
$remark->doctors_name = $request->input('doctors_name');
$remark->appointment_date = $request->input('appointment_date');
$remark->approval_date =Carbon::now();
$remark->ir_status = 'approved';
$remark->save();
//approvalrecord
$approval = new ApprovalModel;
$approval->req_id = $request->request_id;
$approval->approver_id = Auth::user()->id;
$approval->category = 'Insurer | Verified By: ';
$approval->status = 'Verified';
$approval->comment = $request->input('comment');
$approval->save();
//email to all medical team
if( !$remark->save() || !$approval->save() )
{
DB::rollback();
return back()->withInput(Input::all())->with('failure', 'Transaction Not Successful. Check the input data');
}
DB::commit();
return redirect('/insurer-view-submitted-requests')->with('success', 'Referral Request Approved Successfully');
}
Replace this line
$referral_model = ReferralRequestModel::where('request_hash', $request_hash)->firstOrFail();
Because you are replacing the $request with a model instance and trying to get the value using $request->input('hosp_no') something like that
$request->input('hosp_no') that method will try to get input method from your ReferralRequestModel
so replace the above line and use $referral_model where you want.
also suggest to use try , catch block for handle exception. because firstOrFail throw Illuminate\Database\Eloquent\ModelNotFoundException exception if data is not found
I am trying to add link to downloadable product programmatically, below is the code on which i am working.
$linkfile = array();
$_highfilePath = $FolderPath.DS.$fname;
$linkfile[] = array(
'file' => $filePath,
'name' => $fname,
'size' => filesize($filePath),
'status' => 'new'
);
$linkFileName = Mage::helper('downloadable/file')->moveFileFromTmp(
Mage_Downloadable_Model_Link::getBaseTmpPath(),
Mage_Downloadable_Model_Link::getBasePath(),
$linkfile
);
$linkModel = Mage::getModel('downloadable/link')->setData(array(
'product_id' => $product->getId(),
'sort_order' => 0,
'number_of_downloads' => 0, // Unlimited downloads
'is_shareable' => 2, // Not shareable
'link_url' => '',
'link_type' => 'file',
'link_file' => json_encode($linkfile),
'sample_url' => $SamplePathUrl,
'sample_file' => json_encode($linkfile),
'sample_type' => 'file',
'use_default_title' => true,
'default_price' => 0,
'price' => 0,
'store_id' => 0,
'website_id' => $product->getStore()->getWebsiteId(),
));
and this is the error i get An error occurred while saving the file(s)..
Please help
Impossible to diagnose with certainty without more information. Here's the code for the call that's failing:
/**
* Checking file for moving and move it
*
* #param string $baseTmpPath
* #param string $basePath
* #param array $file
* #return string
*/
public function moveFileFromTmp($baseTmpPath, $basePath, $file)
{
if (isset($file[0])) {
$fileName = $file[0]['file'];
if ($file[0]['status'] == 'new') {
try {
$fileName = $this->_moveFileFromTmp(
$baseTmpPath, $basePath, $file[0]['file']
);
} catch (Exception $e) {
Mage::throwException(Mage::helper('downloadable')->__('An error occurred while saving the file(s).'));
}
}
return $fileName;
}
return '';
}
A good place to start would be checking filesystem permissions, making sure your datatypes match the types specified in the function comments, and making sure all files and directories exist.