PHP with outlook

Hello,

I'm sorry I'm very new to PHP and I'm wondering if I try to learn this language can this language use Microsoft outlook - are they compatible? If it can't then what are my alternatives to outlook? I mean another email client that I can use.

If it can, I mean it is compatible with Microsoft Outlook is it possible that the PHP application or software I'm trying to build send a message to outlook without an internet connection; yes both Microsoft Outlook and PHP application are in one local machine, let us say my laptop or our own office server and it happened that I lost internet connection. Can it que my email then when there is an internet connection it will send the email to our hosting or server somewhere.

For you to understand my question better, I'm going to learn PHP language and use it to create an application that will be installed in a local computer let us say in a remote island where the internet sometimes disappear I still want that application to function then save the data it will produce to Microsoft outlook and when the internet resumes or there is an internet connection it will send automatically to our server in our office in the city.

This application is useful let us say in an oil platform or oil rig which was hit by a storm so the internet was disrupted I still want the application to function without the internet then save whatever it is trying to do and send it to the internet when the internet connection has returned.

I hope I made myself clear
prinLeAAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Kanti PrasadCommented:
HI

Php mailer is an alternative
http://phpmailer.worxware.com/index.php?pg=tutorial

Outlook needs to connect to SMTP server in order to send emails with or without attachments and you can use PHP to send emails through outlook.

Even if you are disconnected to the internet for a while once you are connected you can open emails you’ve already received even when you aren’t connected to the internet.

You need a COM object to connect to outlook via php.

if (!defined("olMailItem")) {define("olMailItem",0);}
$oApp  = new COM("Outlook.Application") or die('error');
$oMsg = $oApp->CreateItem(olMailItem);
$oMsg->Recipients->Add("xxx@xxx.org");
$oMsg->Subject=$subject;
$oMsg->Body=$message;
$oMsg->Save();
$oMsg->Send();

Here is more info on outlook.
https://support.office.com/en-ie/article/How-to-use-Outlook-and-Outlook-com-together-b8625006-d062-44af-baf8-26c63b880f53
2
Ray PaseurCommented:
If you're new to PHP and want some good learning resources, this article can help you find them.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_11769-And-by-the-way-I-am-new-to-PHP.html
1
gr8gonzoConsultantCommented:
What you're describing is a little more complicated than you probably think, so I'm going to break this down into small pieces:

1. Outlook itself is just an email client. Email clients don't really have the capability to send out emails. Instead, when you write and "send" a message in Outlook (or in PHP or whatever), the message is ACTUALLY being handed over to an email server. The email server is the one that actually sends the message to the intended destination.

2. Without an internet connection (oil rig or whatever), usually an email client like Outlook cannot connect to its email server, so it will queue it up, like you said.

3. Outlook does have the capability of having plug-ins (called add-ins), and add-ins are basically tiny programs that use a special programming library called an SDK (Software Development Kit). There is an SDK for all Office applications, including Outlook, but the SDK can only be used by certain programming languages that can "speak" its language. The add-ins have to be compiled down into DLL files that Office applications can then load.

4. PHP is not a language that can do this. There's a TINY chance that someone has figured out how to make it all work, but it's basically like hammering a square block into a round hole - PHP is just not designed for this kind of use.

5. A language that CAN build Office add-ins is .NET, such as C# or Visual Basic.NET (I prefer C#, since it's most similar to object-oriented PHP), and they work wonderfully. You COULD, in theory, write a C# add-in that will watch a specific folder on a computer and any time a message is saved into that folder, it could read the message and save it into Outlook, but Outlook would have to be running all the time for this to work. PHP could then just write the message to that folder and let the add-in read the message and queue it up in Outlook.

6. The above suggestion is probably the most complicated way to do it, but it's workable. An easier way...

7. ...is to not use Outlook for queuing and sending the messages. You can install a very lightweight e-mail server application on any computer. That e-mail server can usually be configured to be a "relay", where it can act like an e-mail server and queue up messages, but instead of actually sending them itself, it can relay the messages to another email server whenever it gets a connection. Then you can configure PHP so that when you try to use mail(), it will send the message to that e-mail server application, which will then take on the responsibility of waiting for a connection, and then passing on the queued messages.

8. ...OR an even simpler way would be to simply test to see if the mail() function fails or succeeds. If it fails because there's no internet connection, save the message contents to a folder somewhere. Then have another PHP script that will run every 10 minutes or something (you can use the Windows scheduler), and then have that PHP script simply look for any messages in that folder, and if it finds any, it tries to send them. If it succeeds (because there is an internet connection), the message is deleted. If it fails, the message stays in the folder. This way is a little more crude, but it doesn't need you to install a mail server application.
2

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Ray PaseurCommented:
I have very little to add to the excellent information @gr8gonzo provided here, but just a note about email.  It may seem simple because so many people use it.  But it's not simple to write server-side programming for email and it's utterly without accountability, full of spam and malware, and very unevenly supported.  You do not control the email system, and it is full of "spooky action at a distance." Suggest you read the "Return Values" on this man page link carefully.  You may need to write some advanced programming to queue your mail messages.  This may not be the perfect place to start your learning adventures in PHP.  It may be worth engaging the assistance of a professional developer, or starting with simpler learning tasks and building up experience before you take on something this full of trap-doors and trip-wires!
1
prinLeAAuthor Commented:
Thank you so much for the information I really appreciate your help.
0
prinLeAAuthor Commented:
Thanks for all the comment or help I appreciate it guys. All comments help actually if only I can give points to everyone that made the comment.
0
prinLeAAuthor Commented:
Hello,

Just a follow up question to gr8gonzo, you said:

PHP is not a language that can do this. There's a TINY chance that someone has figured out how to make it all work, but it's basically like hammering a square block into a round hole - PHP is just not designed for this kind of use.

If PHP is not designed for this kind of use then what email client would you suggest that is compatible with PHP? Of course that can also run on a Microsoft Windows since most computers are using Microsoft Windows. Install that email server and with an email client then still use PHP. Or I got it wrong it's really not possible I should be studying C# or .net instead of PHP.
0
prinLeAAuthor Commented:
Just to make the follow up question clearer.

I prefer to use PHP because it can be deployed easily on any web hosting company in the US. If it's .net well it can also be used in most servers but there are abundant tutorial and community using PHP so much easier for me to learn and get script from other experts using it.

So I will be developing a software that can be deployed on the web so it is web based but this must be cross-platform because many computers such as laptops and desktops are using Windows so the software can also be installed there and use an email client and the email server would send the message to a far away server, let say in Singapore or in the US. The software must still function on a local machine just like a desktop application even without an internet and when the internet connection is back it can send data through email to the server in the US or Singapore.
0
gr8gonzoConsultantCommented:
You can split up points between multiple comments, by the way. If you'd like to split them up, just say the word and an admin can unmark the accepted answer and there should be a button for marking all applicable comments that you like as answers.

> If PHP is not designed for this kind of use then what email client would you suggest that is compatible with PHP?

Well, PHP does have its own e-mail client (the mail() function), and as someone else mentioned, you can have 3rd party mail client scripts like PHPMailer. What I was saying is that you cannot (to my knowledge) write PHP and turn it into a DLL file that uses the Office SDK and acts as a proper add-in for Office applications. If you want to build programs that control Office apps (e.g. put a message into Outlook's outgoing mail folder to be queued up), then it's probably better to learn C#.

If you just want to meet the need of queuing and sending email when internet connectivity is restored, then you can do that with PHP without involving Outlook at all.

There ARE caveats to some of what you're talking about, though. If you want something that is going to be deployed in many locations (just reading between the lines of your last comment), then there are more aspects of email that you have to consider. Successful e-mail-driven solutions are a little tricky to build. You usually have to understand SPF, DKIM, blacklists, and relays. For example, SPF rules can dictate what e-mail servers are allowed to send email on behalf of a given domain name. If your application sends out e-mails based on a constant domain name without taking stuff like SPF into consideration, then you might build out your application only to discover that all your emails are getting blocked. So I would suggest reading up on e-mail delivery and security before you start programming anything.

If you write a C# add-in that simply manipulates the outgoing mail folder of Outlook, then you probably aren't going to have the same problems. Chances are that Outlook will already be configured and prepared properly by a network admin or what not, and e-mails coming via Outlook will probably go through just fine.

However, a C# add-in is not going to be a web-based solution (at least it probably wouldn't be - you can do just about anything in C#, but it's not a typical approach).

Still, C# is going to likely be a better language if you want something that is primarily driven by Windows and acts like a desktop application. I'm on the fence about whether that's something you really want.

If you go with PHP and you want a solution that is web-based and very portable, then it's probably better to NOT install an e-mail server, because you might not be able to do that in all your locations. It's one thing if you're just developing a client-side solution for a small, controllable group of workstations, but your last message sounds like you're getting more into server-side usage, so the scheduled PHP script would probably be a better route if you think PHP is a better fit for you.

Honestly, this is one of those things where knowing all the requirements would definitely help in recommending solutions, but if there are a lot of them, then you might be better off finding a veteran developer who can do this for you and do it well.
1
prinLeAAuthor Commented:
Hello,

Thank you so much gr8gonzo I really appreciate your comment and help.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Email Clients

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.