Instantiate phpmailer in a separate class?

This is a discussion on Instantiate phpmailer in a separate class? within the PHP General forums, part of the PHP Programming Forums category; Hello, I want to have a class send some emails. I wanted to use the excellent phpMailer class to do ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 11-29-2007
Mike Yrabedra
 
Posts: n/a
Default Instantiate phpmailer in a separate class?


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^)>
Reply With Quote
  #2 (permalink)  
Old 11-29-2007
Jochem Maas
 
Posts: n/a
Default Re: [PHP] Instantiate phpmailer in a separate class?

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


>
>

Reply With Quote
  #3 (permalink)  
Old 11-29-2007
Mike Yrabedra
 
Posts: n/a
Default Re: [PHP] Instantiate phpmailer in a separate class?

on 11/29/07 1:53 AM, Jochem Maas at jochem@iamjochem.com 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^)>
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 03:01 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0