[PHP] Instantiate phpmailer in a separate class?

2007-11-28 Thread Mike Yrabedra

Hello,

I want to have a class send some emails.

I wanted to use the excellent phpMailer class to do this.

What is the proper way to use the phpMailer class from within a method of a
separate class?


-- 
Mike B^)>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Instantiate phpmailer in a separate class?

2007-11-28 Thread Jochem Maas
Mike Yrabedra wrote:
> Hello,
> 
> I want to have a class send some emails.
> 
> I wanted to use the excellent phpMailer class to do this.
> 
> What is the proper way to use the phpMailer class from within a method of a
> separate class?

the same way you would use it outside of a method of a class.


class Foo {
function bar() {
$mailer = new phpMailer;
// do stuff with mailer.
}
}


now your Foo class might want to make use of the $mailer object from within
more than one method - in this case you can consider using a property of your
Foo instances.

class Foo {
private $mailer;
function __construct() {
$this->mailer = new phpMailer;
}
function bar() {
$this->mailer->clearAddresses();
}   
function bar() {
$this->mailer->Send();
}
}


> 
> 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Instantiate phpmailer in a separate class?

2007-11-29 Thread Mike Yrabedra
on 11/29/07 1:53 AM, Jochem Maas at [EMAIL PROTECTED] wrote:

> Mike Yrabedra wrote:
>> Hello,
>> 
>> I want to have a class send some emails.
>> 
>> I wanted to use the excellent phpMailer class to do this.
>> 
>> What is the proper way to use the phpMailer class from within a method of a
>> separate class?
> 
> the same way you would use it outside of a method of a class.
> 
> 
> class Foo {
> function bar() {
> $mailer = new phpMailer;
> // do stuff with mailer.
> }
> }
> 
> 
> now your Foo class might want to make use of the $mailer object from within
> more than one method - in this case you can consider using a property of your
> Foo instances.
> 
> class Foo {
> private $mailer;
> function __construct() {
> $this->mailer = new phpMailer;
> }
> function bar() {
> $this->mailer->clearAddresses();
> } 
> function bar() {
> $this->mailer->Send();
> }
> }
> 
> 
>> 
>> 
> 


Very kewl. Thank you.


-- 
Mike B^)>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php