I want to open outlook using php on client machine. I have already PHP code to open outlook window.
Current scenario: I can open outlook using PHP on local server(local machine). say localhost url : http://localhost/openOutlook/index.php It opens the outlook on which system/server where the code is available. It means I have code in my local system.By running that code I can open outlook perfectly.
I am using XAMPP. PHP 7.1. Windows 10. Office 2013. (in my local system) XAMPP, PHP 7.1, server 2008 R2 (on server) Default mail client : outlook
But when I upload the same code on Windows server 2008 R2, IT OPENS outlook on that server it self.
It means, URL: http://serverName/openOutlook/index.php. If I access this link from any system than Ii opens the outlook on the server itself only.
Ideally It should open outlook in client's system.
I checked: it is not a problem of permissions on server or so.
What I want : I want to open outlook using PHP on client machine who is accessing that link. (http:serverName/openOutlook/index.php)
Note : I have enabled: extension=php_com_dotnet.dll
I have referred many links and questions for solution. But unfortunately nothing helped me.
This is my simple code:
<?php
com_load_typelib('Outlook.Application');
$objApp = new COM("Outlook.Application") or die ( "Cannot Load Outlook.Application" );
$namespace = $objApp->GetNamespace("MAPI"); // or MAPI.Session
$namespace->Logon();
$myItem = $objApp->CreateItem ( olMailItem );
$myItem->To = $div_wise_value['emails'];
$myItem->Subject = "Mail subject";
$myItem->HTMLBody = "mail body";
$myItem->Display();
?>
Is it possible to open outlook on any system from which the link is accessed ?
If this isn't possible, than what other approach I can use ?
Any help is appreciated.
Thank you.
答案 0 :(得分:0)
这是不可能的(至少,不是你喜欢的方式)。在服务器上运行的PHP代码可以访问服务器上的COM对象。您正在尝试访问客户端上的COM对象。
理论上,您可以获取有关连接机器IP地址的信息,使用远程COM调用该机器上的功能,但几乎每个防火墙都会尝试阻止它(有充分理由 - 您正在尝试远程控制机器。)
通过HTML或javascript尝试执行此操作会好得多 - 这里有一个适用于某些电子邮件客户端的示例: http://resources.elixiter.com/how-to/how-to-pre-populate-the-subject-line-and-body-in-mailto-generated-emails
如果您真的想要这个(在客户端上打开Outlook),ActiveX就是为了做这种事情而设计的。但是,老实说,这不是一个好主意。即使你可以这样做,如果这个人没有安装Outlook,会发生什么?如果他们不在Windows上怎么办? HTML和JavaScript解决方案适用于更多系统。
答案 1 :(得分:0)
PHP在服务器上运行。要在客户端上运行代码,你几乎只限于IE中的JS,并且只有当你在可信列表上时才允许创建COM对象。
在服务器上创建一个EML文件(包含HTML和所有文件)并让用户下载它。客户端的Outlook将很乐意打开并显示它。不要忘记设置X-Unsent:1
MIME标头,以确保它显示为Outlook未发送。