How To send E-mail using PHP COM functions

COM is a technology which allows the reuse of code written in any language (by any language) using a standard calling convention ...

How to send E-mail using PHP COM functions

What is COM

COM is a technology which allows the reuse of
code written in any language (by any language) using a standard calling convention
and hiding behind APIs the implementation details such as what machine the Component
is stored on and the executable which houses it. It can be thought of as a super
Remote Procedure Call (RPC) mechanism with some basic object roots. It separates
implementation from interface ('PHP Manual')

The Script

Open you favorite text editor and put the following lines:


$objApp = new COM("Outlook.Application");

$myItem = $objApp->CreateItem(olMailItem);

$a=$myItem->Recipients->Add("admin@purplerain.org");

$myItem->Subject="This is a test";

$myItem->Body="This is a Body Section now.....!";

$myItem->Display();

$myItem->Send();

?>

The explanation

$objApp = new COM("Outlook.Application");

In the first line we create a instance of the COM object (in this case your
Outlook Application)

If you have installed MS Outlook, in your Windows registry exists a key named
Outlook.Application

Start Regedit.exe and explore the HKEY_CLASSES_ROOT . There is your Com objects.

$myItem = $objApp->CreateItem(olMailItem);

Creates new MailItem (new Mail)

$a=$myItem->Recipients->Add("admin@purplerain.org");

Adding the Recipient element of MailItem

This will be your recipient

$myItem->Subject="This
is a test";

Adding Subject element

This will be your subject

$myItem->Body="This is
a Body Section now.....!";

Adding the Body element of MailItem

This will be your message

$myItem->Display();

If you want see your Outlook Mail dialog add this line in the script ,else just
comment it!

$myItem->Send();

Send the message using your DEFAULT Outlook account.

 

 

 

 

 

 

Share this article!

Follow us!

Find more helpful articles: