Page 1 of 1

Send outlook mail from PHP script using COM objects

Posted: Sat Jul 25, 2009 3:56 pm
by rrodriguez
Hello Everyone,
My name is Richard, I am new to PHP programing and I am in need of some help. I am working on a PHP project that needs to parse an e-mail template pull out key words to be replaced by information from an HTML form and then create a
an email to be sent via outlook. I created the code to parse the template:

Code: Select all

 
class Parser
{   
    // This Method will:    1. Get the content of a file and convert it to a string
    //                      2. Replace all the carriege return on the string with spaces
    //                      3. Use the spaces to split the string in to an array
    //                      4. compair the array elements to a patern and fine match
    //                      5. store match on a seperate array.
                            
    public function get_field($file){
    $Mail_Text = file_get_content($file);
    $Patern = '/^_[INSERT]{6}+[_A-Z]+[_A-Z]_$/';
    $File_Content = str_replace(chr(13), chr(32), $Mail_Text);
    $aField_Content = explode(chr(32),$File_Content);
    
    
        foreach($aField_Content as $Element){
            if (preg_match($Patern,$Element){
                $aField[].=$Element;
            }
        }
    }
    return true;
}
 
can anyone help me with the COM object? I know how to create the Object but I don't know what methods to use.
Thank you in advance Richard.

Re: Send outlook mail from PHP script using CON objects

Posted: Sat Jul 25, 2009 4:04 pm
by omniuni
Hi rrodriguez,

I'm not sure I quite follow. Let's say we can take a template, parse it, and insert the data (using str_replace() that's quite easy). How do you want to get the output from the PHP script into Outlook? Are you going to generate a *.eml file and present it as a download? Simply output HTML for copy-and-paste?

Some more information would be great, and maybe we can help you along.

Good Luck!

Re: Send outlook mail from PHP script using CON objects

Posted: Sat Jul 25, 2009 4:23 pm
by Weirdan
omniuni wrote:Are you going to generate a *.eml file and present it as a download? Simply output HTML for copy-and-paste?
Using PHP does not necessarily means using HTML, web server, etc. rrodriguez might be developing a local application that does not need browser at all.

Re: Send outlook mail from PHP script using COM objects

Posted: Sat Jul 25, 2009 4:25 pm
by omniuni
Granted, but I am quite unsure how that would work with outlook... oh well, we'll see.

Re: Send outlook mail from PHP script using COM objects

Posted: Sun Jul 26, 2009 3:09 pm
by rrodriguez
Hello again,
Thank you for all your responses. Here is the problem:

At work we use a wiki for the support staff to know how to responce to insidents or a user request. some of the procedures requier an e-mail to be sent out. the real problem is that some of the e-mails a longer than what I can fit in a URL therefore not all of the e-mail links work. I am trying to come up with a solution that when some one clicks on an e-mail link in the wiki a forms pops up so the staff member can enter the necesary information then the form information get put into an email using outlook (we use MS EXCHANGE) in order to be sent out. Outlook is installed locally on each computer. I hope this answers your questions.

thanks
rrodriguez

Re: Send outlook mail from PHP script using COM objects

Posted: Sun Jul 26, 2009 8:56 pm
by omniuni
You can't necessarily control Outlook from the site, but you have two options that I see. Either generate a .eml file, which should open with outlook, and can then be sent, or just let the site send the mail. Just because you're using MS Exchange (ugh.) doesn't mean you can't send mail with your website. Just read in the info, use something like str_replace() to replace the instances of key words with entered information, and let the mail() function do its thing.

Would that work?

Re: Send outlook mail from PHP script using COM objects

Posted: Mon Jul 27, 2009 11:17 am
by rrodriguez
I will give it a try and let you know.

Thank you for the help. :D

Re: Send outlook mail from PHP script using COM objects

Posted: Wed Jul 29, 2009 8:38 pm
by rrodriguez
We opted to go with the mail() function for now, but what I was trying to do with outlook can be done with COM objects. here is a sample of the code:
<?php
$outlook =new com("outlook.application");
$task = $outlook->CreateItem(0);
$task->To ="recipient@hotmail.com";
$task->Subject="Outlook Test";
$task->Display();
$task->Send();
?>
When running this code I was getting a fatal error: Maximum execution time of 30 seconds exceeded. I will continue to work on it and if I get it to work I will post it here.
Thank you for your help.