Re: Variable Scope problem passing function parameters

From: Date: Thu, 18 Dec 2008 19:14:30 +0000
Subject: Re: Variable Scope problem passing function parameters
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-284805@lists.php.net to get a copy of this message
Jim McIntyre wrote: > I'm new to PHP 5 and classes, but I've done a lot of ActionScript. > > I'm trying to use PHPMailer inside my own class (a service for > AMFPHP). I'm having problems getting the data that'spassed into my > class's send() method to the instance of the PHPMailer. > > Basically, I have this: > > class EmailAMF { > public function send ($from, $to, $subject, $body) { > require('class.phpmailer.php'); > > $phpMail = new PHPMailer(); > $phpMail->From = $from; > $phpMail->AddAddress($this->to); > $phpMail->Subject = $subject; > $phpMail->Body = $body; > return $phpMail->Send(); > > } > } > > As far as I can tell, it sends an essentially blank email to nobody > (but returns true. > > If I replace any of my function variables with strings, like this: > > $phpMail->AddAddress('me@example.com'); > > the email actually "gets" that data. > > What am I missing? > > Thanks, > Jim > $this -> to it has no meaning in the scope of your class.

« previous php.general (#284805) next »