I've been using php-ews for a month, i able to make a meeting but i want the organizer is the room email / room name that i attend the meeting
so for example, i create a meeting at 8:00am - 10:00am at room1 (room1#mydomain.com), i want the organizer is the room email (room1#mydomain.com) / room name (room1)
i know i can do this in the office 365 (login with my credential ->choose open another mailbox -> choose room1#mydomain.com), but i want to do this via php-ews
i already set the resource mailbox, mailbox delegation property to my login credential
is it possible to change the organizer name to room name / room email??
my basic code:
$host = $selected_exchange->exchange_host;
$username = $exchange_email;
$password = $exchange_password;
$version = $selected_exchange->exchange_version;
$timezone = 'SE Asia Standard Time';
$client = new Client($host, $username, $password, $version);
$client->setTimezone($timezone);
$start = new DateTime($booking_date . $booking_time_start . ":00");
$end = new DateTime($booking_date . $booking_time_end);
$guests = array(
array(
'name' => $room->exchange_room_name,
'email' => $room->exchange_room_email,
)
);
// Set connection information.
$request = new CreateItemType();
$request->SendMeetingInvitations = 'SendOnlyToAll';
//CalendarItemCreateOrDeleteOperationType::SEND_ONLY_TO_ALL;
$request->Items = new NonEmptyArrayOfAllItemsType();
// Build the event to be added.
$event = new CalendarItemType();
$event->RequiredAttendees = new NonEmptyArrayOfAttendeesType();
$event->Start = $start->format('c');
$event->End = $end->format('c');
$event->Subject = $meeting_title;
$event->Location = $room->exchange_room_name;
// Set the event body.
$event->Body = new BodyType();
$event->Body->_ = $special_request . " Meeting Created By: ";
$event->Body->BodyType = 'Text'; //BodyTypeType::TEXT;
// Iterate over the guests, adding each as an attendee to the request.
foreach ($guests as $guest) {
$attendee = new AttendeeType();
$attendee->Mailbox = new EmailAddressType();
$attendee->Mailbox->EmailAddress = $guest['email'];
$attendee->Mailbox->Name = $guest['name'];
$attendee->Mailbox->RoutingType = 'SMTP'; //RoutingType::SMTP;
$event->RequiredAttendees->Attendee[] = $attendee;
}
try
{
// Add the event to the request. You could add multiple events to create more
// than one in a single request.
$request->Items->CalendarItem[] = $event;
$response = $client->CreateItem($request);
// Iterate over the results, printing any error messages or event ids.
$response_messages = $response->ResponseMessages->CreateItemResponseMessage;
foreach ($response_messages as $response_message) {
// Make sure the request succeeded.
if ($response_message->ResponseClass != ResponseClassType::SUCCESS) {
$code = $response_message->ResponseCode;
$message = $response_message->MessageText;
//fwrite(STDERR, "Event failed to create with \"$code: $message\"\n");
$result = array('ok' => 0, 'message' => $message);
continue;
}
// Iterate over the created events, printing the id for each.
foreach ($response_message->Items->CalendarItem as $item) {
$id = $item->ItemId->Id;
//fwrite(STDOUT, "Created event $id\n");
$result = array('ok' => 1, 'message' => 'Success Added To Calendar');
}
}
}
catch(Exception $e)
{
$result = array('ok' => 0, 'message' => $message);
}
I recently had to do this same thing. When I was searching, I found the answer within the Exchange SDK Docs :
https://learn.microsoft.com/en-us/previous-versions/office/developer/exchange-server-2007/bb856541%28v%3dexchg.80%29
With only a few changes, I was able to make it work on the php-ews structure.
Basically you make the room as a distinguished folder and use it as the saved item folder id. The person who is logged in as the user must have Delegate access to the room, and it will automatically send the request from the user on behalf of the room, and the room will be the organizer.
// Set connection information with save copy so that it saves to the folder
$request = new CreateItemType();
$request->MessageDisposition = MessageDispositionType::SEND_AND_SAVE_COPY;
$request->SendMeetingInvitations = CalendarItemCreateOrDeleteOperationType::SEND_TO_ALL_AND_SAVE_COPY;
// Add the Room as the target saved item folder (user must have delagate access to the room)
$roomFolder = new DistinguishedFolderIdType();
$roomFolder->Id = DistinguishedFolderIdNameType::CALENDAR;
$roomFolder->Mailbox = new EmailAddressType();
$roomFolder->Mailbox->EmailAddress = $room->exchange_room_email;
$roomFolder->Mailbox->Name = $room->exchange_room_name;
$target = new TargetFolderIdType();
$target->DistinguishedFolderId = $roomFolder;
$request->SavedItemFolderId = $target;
$request->Items = new NonEmptyArrayOfAllItemsType();
Related
I need to create a document using Google Drive API, then give writer permission to logged in user and redirect them to created file. I'm trying to do it like this:
$credentials = storage_path('credentials.json');
$user = Socialite::driver('google')->stateless()->user();
$token = [
'access_token' => $user->token,
'refresh_token' => $user->refreshToken,
'expires_in' => $user->expiresIn
];
$client = new Google_Client();
$client->setApplicationName('Sheets');
$client->setScopes([Google_Service_Docs::DRIVE, Google_Service_Docs::DOCUMENTS]);
$client->setAccessType('offline');
$client->setAuthConfig($credentials);
$client->setAccessToken($token);
$service = new Google_Service_Docs($client);
$serviceDrive = new Google_Service_Drive($client);
$body = new Google_Service_Drive_DriveFile(array(
"name" => 'Testing ' . Lang::get('pls.export.name')
));
$doc = $serviceDrive->files->create($body);
$permission = $this->insertPermission($serviceDrive, $doc->id, $user->email, 'user', 'writer');
$url = "https://docs.google.com/document/d/" . $doc->id . "/edit#";
return Redirect::away($url);
This is the insertPermission function
function insertPermission($service, $fileId, $value, $type, $role)
{
$newPermission = new Google_Service_Drive_Permission();
$newPermission->setEmailAddress($value);
$newPermission->setType($type);
$newPermission->setRole($role);
if ($role == 'owner') {
$permission = $service->permissions->create($fileId, $newPermission, array('fields' => 'id', 'transferOwnership' => 'true'));
} else {
$permission = $service->permissions->create($fileId, $newPermission);
}
if ($permission) {
return $permission;
}
return NULL;
}
After I run this code, I can see that the file was indeed created (I can get its id too), I also receive a notification on email that the file was shared with me, but I can't open the file itself. I'm getting a notification that page does not exist and "Sorry, unable to open the file at this time".
P.S. The same approach works perfectly fine when I'm creating a spreadsheet, instead of document. I can access the spreadsheet without any issues afterwards
After some research and testing I managed to fix the issue. The problem was I was using google drive api to create the file. Instead, I used Google Docs API like so:
$document = new Google_Service_Docs_Document(array(
'title' => 'Testing ' . Lang::get('pls.export.name')
));
$document = $service->documents->create($document);
Everything worked like a charm
I have a settings page in my admin panel where the user can paste their Google map iframe code (embed code). The setting options are saved in the database and displayed in various places on the front-end.
My problem is that when I save the settings, the map embed code isn't saved to the database. I guess it's a sanitization problem.
Here is my code from my controller:
public function updateGeneral(Request $request) {
$id = $request->id;
$data = array();
$data['site_title'] = $request->site_title;
$data['meta_description'] = $request->meta_description;
$data['site_lang'] = $request->site_lang;
$data['company_name'] = $request->company_name;
$data['address'] = $request->address;
$data['phone'] = $request->phone;
$data['map'] = $request->map;
$data['email'] = $request->email;
$data['facebook'] = $request->facebook;
$data['twitter'] = $request->twitter;
$data['youtube'] = $request->youtube;
$data['insta'] = $request->insta;
// Update table with new data
DB::table('settings')->where('id', $id)->update($data);
return redirect(route('admin.settings'))->with('successMsg', 'Settings have been updated successfully!');
}
So how can I make sure that the data is saved for:
$data['map'] = $request->map;
Sorry, just realized there was a typoo in form name field. But I also had to change the db field from varchar to text.
I'm trying to send e-mails using swiftmailer. I want to send a message to someone who fills out a form, and to myself. The script I use below is sending the first of the two messages, but the second one never arrives. How can I solve this?
$transport = Swift_SmtpTransport::newInstance('smtp.mysite.nl', 25)
->setUsername('myusername')
->setPassword('mypassword')
;
$mailer = Swift_Mailer::newInstance($transport);
// Create the message
$message = Swift_Message::newInstance()
// Set the content type
/* ->setContentType("text/html"); */
// Give the message a subject
->setSubject("mysubject")
// Set the From address with an associative array
->setFrom(array('email#email.com' => "emailer"))
// Set the To addresses with an associative array
->setTo(array('email#email.com' => "emailer"))
// Give it a body
->setBody('My message', 'text/html');
// Create the message
$message2 = Swift_Message::newInstance()
// Set the content type
/* ->setContentType("text/html"); */
// Give the message a subject
->setSubject("mysubject")
// Set the From address with an associative array
->setFrom(array('email#email.com' => "emailer"))
// Set the To addresses with an associative array
->setTo(array('email#email.com' => "emailer"))
// Give it a body
->setBody('My message', 'text/html');
$result = $mailer->send($message, $message2);
In short: $message is sent, $message2 is not sent. I DO NOT GET ANY ERRORS FROM THIS SCRIPT!
Try to use something like:
require_once 'lib/swift_required.php';
// Create the Transport
$transport = Swift_SmtpTransport::newInstance('localhost', 25);
// Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);
// Create a message
$message = Swift_Message::newInstance('Wonderful Subject')
->setFrom(array('john#doe.com' => 'John Doe'))
->setBody('Here is the message itself');
// Send the message
$failedRecipients = array();
$numSent = 0;
$to = array('receiver#domain.org', 'other#domain.org' => 'A name');
foreach ($to as $address => $name)
{
if (is_int($address)) {
$message->setTo($name);
} else {
$message->setTo(array($address => $name));
}
$numSent += $mailer->send($message, $failedRecipients);
}
printf("Sent %d messages\n", $numSent);
Such services usually have different methods of sending multiple emails.
Try sending it one bye one.
$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, "ssl")
->setUsername('yourUsername')
->setPassword('yourPassword');
$mailer = Swift_Mailer::newInstance($transport);
$message = Swift_Message::newInstance('Your message')
->setFrom(array('enquiries#dtect.com' => 'Enquiry'))
->setTo(array('enquiries#dtect.com'))
->setBody("Body content");
$result = $mailer->send($message);
$mailer2 = Swift_Mailer::newInstance($transport);
$message2 = Swift_Message::newInstance('Dtect Report Portal - '.$typeOfEnquiry)
->setFrom(array('enquiries#dtect.com' => 'Enquiry'))
->setTo($emailAddress)
->setBody("Dear ".$name.","."\r\n".
"Thank you for contacting us"."\r\n".
"We will respond to your enquiry as soon as possible"."\r\n".
"Regards");
$result2 = $mailer2->send($message2);
Hope this help.
I am using magento default shipment from the admin side.
so its working fine and sending email to the customers perfectly.
I want to create one script that can send email with the shipment details for all the completed orders in magento. This will be only for certain orders coming through CSV.
My script working fine when we are using the order_id of the processing orders but its not working for the completed orders . and not sending the Order items details in the email
please suggest me any solution for it..
Thanks a lot.
I am using the below script to do so :
function completeShipment($orderIncrementId,$shipmentTrackingNumber,$shipmentCarrierCode){
$shipmentCarrierTitle = $shipmentCarrierCode;
$customerEmailComments = '';
$order = Mage::getModel('sales/order')->loadByIncrementId($orderIncrementId);
if (!$order->getId()) {
Mage::throwException("Order does not exist, for the Shipment process to complete");
}
try {
$shipment = Mage::getModel('sales/service_order', $order)->prepareShipment(_getItemQtys($order));
$arrTracking = array(
'carrier_code' => isset($shipmentCarrierCode) ? $shipmentCarrierCode : $order->getShippingCarrier()->getCarrierCode(),
'title' => isset($shipmentCarrierTitle) ? $shipmentCarrierTitle : $order->getShippingCarrier()->getConfigData('title'),
'number' => $shipmentTrackingNumber,
);
$track = Mage::getModel('sales/order_shipment_track')->addData($arrTracking);
$shipment->addTrack($track);
$shipment->register();
_saveShipment($shipment, $order, $customerEmailComments);
}catch (Exception $e) {
throw $e;
}
return $save;
}
function _getItemQtys(Mage_Sales_Model_Order $order){
$qty = array();
foreach ($order->getAllItems() as $_eachItem) {
if ($_eachItem->getParentItemId()) {
$qty[$_eachItem->getParentItemId()] = $_eachItem->getQtyOrdered();
} else {
$qty[$_eachItem->getId()] = $_eachItem->getQtyOrdered();
}
}
return $qty;
}
function _saveShipment(Mage_Sales_Model_Order_Shipment $shipment, Mage_Sales_Model_Order $order, $customerEmailComments = ''){
$shipment->getOrder()->setIsInProcess(true);
$transactionSave = Mage::getModel('core/resource_transaction')
->addObject($shipment)->addObject($order)->save();
//$emailSentStatus = $shipment->getData('email_sent');
$ship_data = $shipment->getOrder()->getData();
$customerEmail = $ship_data['customer_email'];
$emailSentStatus = $ship_data['email_sent'];
if (!is_null($customerEmail)) {
$shipment->sendEmail(true, $customerEmailComments);
$shipment->setEmailSent(true);
}
return $this;
}
Thanks a lot dagfr...! the below code works for me to get done my task:
function completeShipment($orderIncrementId,$shipmentIncreamentId){
$order = Mage::getModel('sales/order')->loadByIncrementId($orderIncrementId);
$ship_data = $order->getData();
$customerEmail = $ship_data['customer_email'];
$shipment = Mage::getModel('sales/order_shipment')->loadByIncrementId($shipmentIncreamentId);
$customerEmailComments = '';
$sent = 0;
if (!is_null($customerEmail)) {
$sent = $shipment->sendEmail(true, $customerEmailComments);
$shipment->setEmailSent(true);
}
return $sent;
}
Your script tries to create the shipment then send the email.
For completed orders the shipment is already created and you can't create it again, so your try fails before the email sending.
Just before :
try {
$shipment = Mage::getModel('sales/service_order', $order)->prepareShipment(_getItemQtys($order));
Check the status of the order, if it's complete, just need to get the shipment and send the mail
$shipment->sendEmail(true, $customerEmailComments);
$shipment->setEmailSent(true);
Else you can perform your script.
I found success using the order_shipment_api instead of the service_order model.
If you want to include the tracking number in the shipment email, make sure you add the tracking first and then use Mage::getModel('sales/order_shipment_api')->sendInfo($shipmentIncrementId).
Code Snippet:
$shipmentApi = Mage::getModel('sales/order_shipment_api');
//pass false for email, unless you want Magento to send the shipment email without any tracking info
//could also be written as $shipmentIncrementId = $shipmentApi->create($order->getIncrementId());
$shipmentIncrementId = $shipmentApi->create($order->getIncrementId(), array(), '' , false, 0);
//add tracking info ($shippingCarrier is case sensitive)
$shipmentApi->addTrack($shipmentIncrementId, $shippingCarrier, $shippingTitle, $trackingNumber);
//send shipment email with tracking info
$shipmentApi->sendInfo($shipmentIncrementId);
See app\code\core\Mage\Sales\Model\Order\Shipment\Api.php for all methods.
You can(should) also perform checks first:
//check for existing shipments if you want
if ($order->getShipmentsCollection()->count() == 0){
}
// and/or
if($order->canShip()){
}
I develop my store in magento community edition 1.5.0.1. I need a Email template that content will be editable by admin. I create a email template through admin "Transactional Emails". Now I need to access and use that email from my custom module. How do I get it?, you have any idea let me know.
This should do it.
public function sendTransactionalEmail() {
// Transactional Email Template's ID
$templateId = 1;
// Set sender information
$senderName = Mage::getStoreConfig('trans_email/ident_support/name');
$senderEmail = Mage::getStoreConfig('trans_email/ident_support/email');
$sender = array('name' => $senderName,
'email' => $senderEmail);
// Set recepient information
$recepientEmail = 'john#example.com';
$recepientName = 'John Doe';
// Get Store ID
$storeId = Mage::app()->getStore()->getId();
// Set variables that can be used in email template
$vars = array('customerName' => 'customer#example.com',
'customerEmail' => 'Mr. Nil Cust');
$translate = Mage::getSingleton('core/translate');
// Send Transactional Email
Mage::getModel('core/email_template')
->sendTransactional($templateId, $sender, $recepientEmail, $recepientName, $vars, $storeId);
$translate->setTranslateInline(true);
}