none
Send a email using COM Outlook object with PHP RRS feed

  • General discussion

  • Hello everybody:

    I am developing a php function that sends an email using Outlook COM object.
    I am able to logon to my outlook client profile. I am able to read my outlook calendars and other things, but when I try to send an email, the action never ends. The message is saved on draft folder.

    I attach the code I use for sending an email:

        $mailitem = $this->myOlApp->CreateItem(Outlook_ItemType::olMailItem);
        $mailitem->To='somebody@hotmail.com';
        $mailitem->Subject='tema';
        $mailitem->Body='hola';
        $mailitem->Save(); //the message is being saved on draft folder
        $mailitem->Send(); //the action remains active and never ends

    Anyone colud help me please?

    Thanks in advance.

    xescjp

    Tuesday, October 2, 2012 12:01 PM

All replies

  • You need to start the message transport. Try calling the NameSpace.SendAndReceive() method.

    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "xescp" <=?utf-8?B?eGVzY3A=?=> wrote in message news:c984049f-397e-4f55-bc5b-d5cba0a46a52...

    Hello everybody:

    I am developing a php function that sends an email using Outlook COM object.
    I am able to logon to my outlook client profile. I am able to read my outlook calendars and other things, but when I try to send an email, the action never ends. The message is saved on draft folder.

    I attach the code I use for sending an email:

        $mailitem = $this->myOlApp->CreateItem(Outlook_ItemType::olMailItem);
        $mailitem->To='somebody@hotmail.com';
        $mailitem->Subject='tema';
        $mailitem->Body='hola';
        $mailitem->Save(); //the message is being saved on draft folder
        $mailitem->Send(); //the action remains active and never ends

    Anyone colud help me please?

    Thanks in advance.

    xescjp


    Ken Slovak MVP - Outlook
    Tuesday, October 2, 2012 2:50 PM
    Moderator
  • Hello Ken:

    I have called SendAndReceive() method but I get the same result. Nothing happens.
    The thread remains hanging. I've also tried to avoid Save() step, but nothing changes.

    Thanks a lot.

    xescjp

    Wednesday, October 3, 2012 6:24 AM
  • I don't use PHP, so I'm not sure about code for it, but can you release the mail item object and if so does it make a difference?
     
    Where is this code running? Is it running on a desktop machine where Outlook is installed and running from a client process and not a service or from server side code?

    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "xescp" <=?utf-8?B?eGVzY3A=?=> wrote in message news:100ee0ff-7628-47e0-83d1-8a520003c219...

    Hello Ken:

    I have called SendAndReceive() method but I get the same result. Nothing happens.
    The thread remains hanging. I've also tried to avoid Save() step, but nothing changes.

    Thanks a lot.

    xescjp


    Ken Slovak MVP - Outlook
    Wednesday, October 3, 2012 2:37 PM
    Moderator
  • Hello Ken:

    Thank you for your interest and help. I have found a solution. I have decided to use mail pear in php.
    It sends an email using smtp. It's easy to use. The inconvenient is that our exchange server is configurated for denying all emails with external destination (for securty reasons) . In my case I can manage to avoid sending external emails.

    Thanks a lot Ken.

    xescjp

    Thursday, October 4, 2012 11:27 AM