duanhuihui2705 2014-04-29 12:50
浏览 81

从php发送邮件使用Outlook 2010

I'm trying to send a Mail via the installed Outlook 2010 Client from my PHP application So far I've tried this suggestion, the top rated answer didn't work for me. Then I added

[COM_DOT_NET]
extension=php_com_dotnet.dll

at the end of php.ini (C:/xampp/php).

I also checked my registry for EnableDCOM, it is set to 'Y'.

This is the code I'm using:

<?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();
?>

The full error msg:

Warning: Uncaught exception 'com_exception' with message 'Failed to create COM object `Outlook.Application': Aufruf wurde durch Aufgerufenen abgelehnt. ' in C:\projekt_dreiskaen\mailtest.php:3 Stack trace: #0 C:\projekt_dreiskaen\mailtest.php(3): com->com('Outlook.Applica...') #1 {main} thrown in C:\projekt_dreiskaen\mailtest.php on line 3

Fatal error: Maximum execution time of 30 seconds exceeded in...

I'm on Win 7 Enterprise in a large corporate Windows Domain, using my local admin rights to run xampp. About 15 users will need to send e-mails from my application.

Any help would be appreciated :)

  • 写回答

2条回答 默认 最新

  • douhe4336 2015-04-29 05:14
    关注

    For me the next code works just out of the box:

    <?php
    $subject="This is a test message";
    
    $message="This is a Body Section now.....! :)";
    
    $to="someaddress@somedomain.com";
    
    // starting outlook
    
    **com_load_typelib("outlook.application");**
    
    if (!defined("olMailItem")) {define("olMailItem",0);}
    
    $outlook_Obj = new COM("outlook.application") or die("Unable to start Outlook");
    
    //just to check you are connected.
    
    echo "Loaded MS Outlook, version {$outlook_Obj->Version}
    ";
    
    $oMsg = $outlook_Obj->CreateItem(olMailItem);
    
    $oMsg->Recipients->Add($to);
    
    $oMsg->Subject=$subject;
    
    $oMsg->Body=$message;
    
    $oMsg->Save();
    
    $oMsg->Send();
    
    ?> 
    
    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料