php-ews how to set importance when sending an e-mail - exchangewebservices

I am using php-ews to send mails and I cannot find a way to set the importance (priority) of a mail.
Here is my code:
$from = $mail['from'];
$to = $mail['to'];
$subject = $mail['subject'];
$body = $mail['body'];
$msg = new EWSType_MessageType();
if($to && count($to) > 0){
$toAddresses = $this->getAddresses($to);
$msg->ToRecipients = $toAddresses;
}
$fromAddress = new EWSType_EmailAddressType();
$fromAddress->EmailAddress = $from['mail'];
$fromAddress->Name = $from['name'];
$msg->From = new EWSType_SingleRecipientType();
$msg->From->Mailbox = $fromAddress;
$msg->Subject = $subject;
$msg->Body = new EWSType_BodyType();
$msg->Body->BodyType = 'HTML';
$msg->Body->_ = $body;
$msgRequest = new EWSType_CreateItemType();
$msgRequest->Items = new EWSType_NonEmptyArrayOfAllItemsType();
$msgRequest->Items->Message = $msg;
$msgRequest->MessageDisposition = 'SendAndSaveCopy';
$msgRequest->MessageDispositionSpecified = true;
$response = $this->ews->CreateItem($msgRequest);
return $response;
Thank you in advance for your response!

You need to load the EWSType_ImportanceChoicesType class. Your code should look like this:
$from = $mail['from'];
$to = $mail['to'];
$subject = $mail['subject'];
$body = $mail['body'];
$msg = new EWSType_MessageType();
if($to && count($to) > 0){
$toAddresses = $this->getAddresses($to);
$msg->ToRecipients = $toAddresses;
}
$fromAddress = new EWSType_EmailAddressType();
$fromAddress->EmailAddress = $from['mail'];
$fromAddress->Name = $from['name'];
$msg->From = new EWSType_SingleRecipientType();
$msg->From->Mailbox = $fromAddress;
$msg->Subject = $subject;
$msg->Body = new EWSType_BodyType();
$msg->Body->BodyType = 'HTML';
$msg->Body->_ = $body;
$msgRequest = new EWSType_CreateItemType();
$msgRequest->Items = new EWSType_NonEmptyArrayOfAllItemsType();
$msgRequest->Items->Message = $msg;
// Start importance code
$msgRequest->Items->Message->Importance = new EWSType_ImportanceChoicesType();
$msgRequest->Items->Message->Importance->_ = EWSType_ImportanceChoicesType::HIGH;
// End importance code
$msgRequest->MessageDisposition = 'SendAndSaveCopy';
$msgRequest->MessageDispositionSpecified = true;
$response = $this->ews->CreateItem($msgRequest);
return $response;
To change the importance just change the ending of the following line to have HIGH, LOW or NORMAL:
$msgRequest->Items->Message->Importance->_ = EWSType_ImportanceChoicesType::HIGH;

I'm not realy familiar with php, but if I'm using C# the mailmessage-class has a "Importance" property which is an enum and can be set to: High, Low and Normal. Default is "Normal".
Hope this helps you...

Related

Can not save data but the message has been save

I have created Cake PHP 3, I want to add data, but when I clik submit button, the data is didn't save but the message show data has been save. I add into two different tables. When I try to add data in one table is fine.
This is my controller
StoreController.php
public function add()
{
$this->loadComponent('General');
$setStatus = 1;
$store = $this->Stores->newEntity();
if ($this->request->is('post')) {
// dd( $this->request->getData());exit;
$connection = ConnectionManager::get('ora');
$connection->begin();
$store = $this->Stores->patchEntity($store, $this->request->getData());;
$merchantTable = TableRegistry::get('MasterFile.Merchants');
$merchant = $merchantTable->find()->where(['MERCHANT_CODE'=>$store->MERCHANT_CODE])->first();
$store->MERCHANT_ID = $merchant->MERCHANT_ID;
$store->CREATED_DATE = date("Y-m-d h:i:s");
$store->LAST_UPDATED_DATE = date("Y-m-d h:i:s");
$store->LAST_APPROVED_DATE = date("Y-m-d h:i:s");
$store->LAST_VERSION_DATE = date("Y-m-d h:i:s");
// $store->store_address->LINE1 = $store->LINE1;
// Start - Controller Code to handle file uploading
if(!empty($this->request->data['STORE_LOGO']['name']))
{
$file = $this->request->data['STORE_LOGO']; //put the data into a var for easy use
$ext = substr(strtolower(strrchr($file['name'], '.')), 1); //get the extension
$arr_ext = array('jpg', 'jpeg', 'png'); //set allowed extensions
$fileName = $this->request->data['STORE_LOGO']['name'];
$uploadPath = WWW_ROOT.'img/store_logo/';
$uploadFile = $uploadPath.$fileName;
//only process if the extension is valid
if(in_array($ext, $arr_ext))
{
if(move_uploaded_file($this->request->data['STORE_LOGO']['tmp_name'],$uploadFile))
{
$store['STORE_LOGO'] = $uploadFile;
}
}
}
if(!empty($this->request->data['BACKGROUND_PICTURE']['name']))
{
$fileName = $this->request->data['BACKGROUND_PICTURE']['name'];
$uploadPath = WWW_ROOT.'img/background_picture/';
$uploadFile = $uploadPath.$fileName;
if(move_uploaded_file($this->request->data['BACKGROUND_PICTURE']['tmp_name'],$uploadFile))
{
$store['BACKGROUND_PICTURE'] = $uploadFile;
}
}
// now do the save
if ($this->Stores->save($store)) {
$setStatus = 1;
$message = 'The store has been saved.';
if($setStatus == 1){
$this->loadComponent('General');
$this->loadModel('MasterFile.Addresss');
$setStatus = 1;
$address = $this->Addresss->newEntity();
//dd($this->request->data);
$this->request->data['Address']['LINE1'] = $this->request->data['LINE1'];
$this->request->data['Address']['LINE2'] = $this->request->data['LINE2'];
$this->request->data['Address']['LINE3'] = $this->request->data['LINE3'];
//dd($this->request->data['Address']);
$connection = ConnectionManager::get('ora');
$connection->begin();
$address = $this->Addresss->patchEntity($address, $this->request->data['Address']);
// dd($address);
// now do the save
if ($this->Addresss->save($address)) {
$setStatus = 1;
$message = 'The store has been saved.';
}else{
$setStatus = 0;
$message = 'The store could not be saved. Please, try again.';
}
$this->Flash->set(__($message));
}
}else{
$setStatus = 0;
$message = 'The store could not be saved. Please, try again.';
}
$this->Flash->set(__($message));
if($setStatus){
$connection->commit();
return $this->redirect(['action' => 'index']);
}else {
$connection->rollback();
}
}
$this->set(compact('store'));
$this->set('_serialize', ['store']);
}
What should i do?
Thank you for your help!
Try debugging the entity:
if ($this->Stores->save($store)) {
debug($store);
...

Skip the first line of a CSV file in Yii2

public function actionUpload(){
$model = new CsvForm();
if($model->load(Yii::$app->request->post())){
$file = UploadedFile::getInstance($model,'file');
$filename = 'Data.'.$file->extension;
$upload = $file->saveAs('uploads/'.$filename);
if($upload){
define('CSV_PATH','uploads/');
$csv_file = CSV_PATH . $filename;
$filecsv = file($csv_file);
print_r($filecsv);
foreach($filecsv as $data){
$modelnew = new Customer1();
$hasil = explode(",",$data);
$nim = $hasil[0];
$nama = $hasil[1];
$jurusan = $hasil[2];
$angkatan = $hasil[3];
$modelnew->username = $nim;
$modelnew->firstname = $nama;
$modelnew->lastname = $jurusan;
$modelnew->password = $angkatan;
$modelnew->save();
}
unlink('uploads/'.$filename);
return $this->redirect(['site/index']);
}
}else{
return $this->render('upload',['model'=>$model]);
}
}
This is my CSV data
user1,name,pass,info
user2,name,pass,info
etc..,
So I want to skip Bold content and proceed my execution.
You could shift the array
$filecsvtemp = file($csv_file);
$filecsv = array_shift($filecsvtemp );
in this way the first row of the array is not present in the resulting array
otherwise use a counter
$cnt = 0;
$filecsv = file($csv_file);
print_r($filecsv);
foreach($filecsv as $data){
if ($cnt!=0){
$modelnew = new Customer1();
$hasil = explode(",",$data);
$nim = $hasil[0];
$nama = $hasil[1];
$jurusan = $hasil[2];
$angkatan = $hasil[3];
$modelnew->username = $nim;
$modelnew->firstname = $nama;
$modelnew->lastname = $jurusan;
$modelnew->password = $angkatan;
$modelnew->save();
}
$cnt++;
}

Laravel nesting json response

i want to create json like this my json in my api controller in laravel.
here the controller
$data = [];
foreach ($products as $p => $product) {
$components = [];
$product_obj = new StdClass();
$product_obj->id = $product->id;
$product_obj->name = $product->name;
$product_obj->category_id = $product->category_id;
//$product_obj->category_name = $product->category->name;
$product_obj->sku = $product->sku;
$product_obj->weight = $product->weight;
$product_obj->discount_type = $product->discount_type;
$product_obj->additional_price = $product->additional_price;
$product_obj->discount = $product->discount;
$product_obj->start_discount = $date_start;
$product_obj->end_discount = $date_end;
$product_obj->thumbnail = $product->thumbnail;
$product_obj->mime_content_type = $product->mime_content_type;
$product_obj->description = $product->description;
$product_obj->is_active = $product->is_active;
//$product_obj->created_at = $product->created_at;
//$product_obj->updated_at = $product->updated_at;
foreach ($product->components()->get() as $c => $component) {
$item_arr = [];
$component_obj = new StdClass();
$component_obj->id = $component->id;
$component_obj->product_id = $component->product_id;
$component_obj->item_id = $component->item_id;
$component_obj->quantity = $component->quantity;
$component_obj->is_mandatory = $component->is_mandatory;
$component_obj->is_customqty = $component->is_customqty;
//$component_obj->created_at = $component->created_at;
//$component_obj->updated_at = $component->updated_at;
$component_obj->quantity_step = $component->quantity_step;
$component_obj->display_order = $component->display_order;
$component_obj->quantity_display = $component->quantity_display;
$component_obj->default_template = $component->default_template;
foreach ($component->item()->get() as $i => $item) {
$item_option_groups = [];
//$options = [];
$item_templates = [];
$item_backgrounds = [];
$item_background_images = [];
$item_obj = new StdClass();
$item_obj->id = $item->id;
$item_obj->name = $item->name;
$item_obj->price = $item->price;
$item_obj->width = $item->width;
$item_obj->height = $item->height;
$item_obj->allow_image_upload = $item->allow_image_upload;
foreach ($item->itemOptionGroups()->get() as $iog => $item_option_groups) {
$item_option_groups = [];
$item_option_groups_obj = new StdClass();
$item_option_groups_obj->id = $item_option_groups->id;
$item_option_groups_obj->name = $item_option_groups->name;
//miising item option on databse
foreach ($item->options()->get() as $io => $item_options) {
$option = [];
$item_options_obj = new StdClass();
$item_options_obj->id = $item_options->id;
$item_options_obj->item_id = $item_options->item_id;
$item_options_obj->item_group_id = $item_options->item_group_id;
$item_options_obj->option_id = $item_options->option_id;
foreach ($item->option()->get() as $o => $item_options) {
$option_obj = new StdClass();
$option_obj->id = $option->id;
$option_obj->name = $option->name;
$option_obj->price = $option->price;
$option[] = $option_obj;
}
$item_options_obj->option = $item_options->option;
$item_options[] = $item_options_obj;
}
$item_option_groups_obj->item_option_group = $item_option_groups;
$item_option_groups[] = $item_option_groups_obj;
//$component_obj->item = $item_arr;
//$components[] = $component_obj;
}
foreach ($item->itemTemplates()->get() as $it => $item_templates) {
$template = [];
$item_templates_obj = new StdClass();
$item_templates_obj->id = $item_templates->id;
$item_templates_obj->template_id = $item_templates->template_id;
$item_templates_obj->item_id = $item_templates->item_id;
foreach ($item->template()->get() as $t => $template) {
$template_obj = new StdClass();
$template_obj->id = $template->id;
$template_obj->name = $template->name;
$template_obj->row = $template->row;
$template_obj->col = $template->col;
$template_obj->thumbnail = $template->thumbnail;
$template_obj->margin = $template->margin;
$template_obj->padding = $template->padding;
$template[] = $template_obj;
}
$item_templates_obj->template = $template;
$item_templates[] = $item_templates_obj;
}
foreach ($item->itemBackgrounds()->get() as $ib => $item_backgrounds) {
$background_color = [];
$item_backgrounds_obj = new StdClass();
$item_backgrounds_obj->id = $item_backgrounds->id;
$item_backgrounds_obj->item_id = $item_backgrounds->item_id;
$item_backgrounds_obj->background_color_id = $item_backgrounds->background_color_id;
foreach ($item->background_color()->get() as $bc => $background_color) {
$background_color_obj = new StdClass();
$background_color_obj->id = $background_color->id;
$background_color_obj->color = $background_color->color;
$background_color[] = $background_color_obj;
}
$item_backgrounds_obj->background_color = $background_color;
$item_backgrounds[] = $item_backgrounds_obj;
}
foreach ($item->itemBackgroundImages()->get() as $ibi => $item_background_images) {
$background_image = [];
$item_background_images_obj = new StdClass();
$item_background_images_obj->id = $item_background_images->id;
$item_background_images_obj->item_id = $item_background_images->item_id;
$item_background_images_obj->background_image_id = $item_background_images->background_image_id;
foreach ($item->background_image()->get() as $bi => $background_image) {
$background_image_obj = new StdClass();
$background_image_obj->id = $background_image->id;
$background_image_obj->image = $background_image->image;
$background_image[] = $background_image_obj;
}
$item_background_images_obj->background_image = $background_image;
$item_background_images[] = $item_background_images_obj;
}
$item_obj->item_option_groups = $item_option_groups;
//$item_obj->item_option_groups = $options;
$item_obj->item_templates = $item_templates;
$item_obj->item_backgrounds = $item_backgrounds;
$item_obj->item_background_images = $item_background_images;
$item_arr[] = $item_obj;
}
$component_obj->item = $item_arr;
$components[] = $component_obj;
}
$product_obj->product_components = $components;
$data[] = $product_obj;
}
if(count($data) == 1){
$data = $data[0];
}
return response()->json($data);
}
}
and this is what i get from this controller json can anyone solve my this ? looks like the nesting going wrong. please help.
About json responses, you could use Laravel's built-in JSON response for this.
So, instead of building the json fields yourself, let laravel do it for you, like this:
return \Response::json( /* Array||Object to be converted */ );
//or
return response()->json( /* Array||Object to be converted */ );
And about the nested relationships that might not be loaded. Assuming that 'products', and 'items...' are Models:
I think a good way would be to use the 'with' or 'load' methods from your model, like this:
$products->load('components');
If you need multiple nested relationships, you can use the 'dot notation' like described in this question
Hope it helps.
Laravel response function automatically convert an array to JSON.
For example in my controller i have following:
$return_data = array('data' => 'some data','response' => 1);
return response($return_data);
Also The json method will automatically set the Content-Type header to application/json, as well as convert the given array to JSON using the json_encode PHP function:
return response()->json([
'name' => 'Abigail',
'state' => 'CA'
]);
For more details you can visit: https://laravel.com/docs/5.1/responses#json-responses

AegisImplicitMail asp.net html body email

I am trying to send mail in asp.net whit AegisImplicitMail. My code is:
string OggettoEmailIta = "Oggetto email";
string TestoEmailIta = "<p>aaa</p><br/><div>bbb</div>";
var mailMessage = new MimeMailMessage();
mailMessage.Subject = OggettoEmailIta;
mailMessage.IsBodyHtml = true;
mailMessage.Body = TestoEmailIta;
mailMessage.Sender = new MimeMailAddress("XXX", "XXX");
mailMessage.From = new MimeMailAddress("XXX", "XXX");
mailMessage.To.Add(new MimeMailAddress("XXX", "XXX"));
mailMessage.To.Add(new MimeMailAddress("XXX", "XXX"));
var emailer = new SmtpSocketClient();
emailer.Host = "smtp.XXX.XX";
emailer.Port = 465;
emailer.SslType = SslMode.Ssl;
emailer.User = "XXX";
emailer.Password = "XXX";
emailer.AuthenticationMode = AuthenticationType.Base64;
emailer.MailMessage.IsBodyHtml = true;
emailer.MailMessage = mailMessage;
emailer.SendMailAsync();
The mail is sent correctly but it is not in HTML format.
Can someone help me?
you might try string literals "#" for your html message, so all chars are kept
string TestoEmailIta = #"<p>aaa</p><br/><div>bbb</div>";

Pagination in smarty

I want to add pagination in my site when user search for some item. I have tried the following code:
//Array Declaration//
$pages = array();
$userlist = array();
//paging variable//
$userlist_pg = $_GET['list_pg'];
if(empty($userlist_pg))
$userlist_pg = 1;
else
$userlist_pg=$_GET['list_pg'];
$userlist_limit = 10;//ADMIN_ITEMLIST_PER_PAGE;
$userlist_start = (($userlist_pg - 1) * $userlist_limit );
$userlist_currentpage = $userlist_pg;
$userlist_back = $userlist_pg-1;
$userlist_next = $userlist_pg + 1;
$query_string = "select cms_id,cms_variable,cms_page_name,cms_last_edited from tbl_cms";
//Paging variables start from here-------------------------
$orderlist = array();
$paging = new PagedResults();
$paging->TotalResults = table_query_count($query_string);
$InfoArray = $paging->InfoArray();
$query_string.=" LIMIT ".$InfoArray["MYSQL_LIMIT1"].", ".$InfoArray["MYSQL_LIMIT2"];
$PageVarName = 'client_page';
$smarty->assign("page_display", getpagelist($InfoArray["CURRENT_PAGE"],$InfoArray["PREV_PAGE"],$InfoArray["NEXT_PAGE"],$InfoArray["TOTAL_PAGES"],$InfoArray["Second_next"],$InfoArray["third_next"],$InfoArray["fourth_next"],$PageVarName));
$smarty->assign("currentpage",$InfoArray["CURRENT_PAGE"]);
$smarty->assign("total_pages",$InfoArray["TOTAL_PAGES"]);
//Paging variables end here-------------------------
it gives the following errors.
Call to undefined function table_query_count() in /home/www/jobplacement4u.com/hungry_uni/modules/search/action/search_action.php on line 110
Class 'PagedResults' not found in /home/www/jobplacement4u.com/hungry_uni/modules/search/action/search_action.php on line 30
Call to undefined method PagedResults::InfoArray() in /home/www/jobplacement4u.com/hungry_uni/modules/search/action/search_action.php on line 111
Looks like you forgot to include the file(s) with definition of function table_query_count and class PagedResults