请问各位大侠这是什么问题? Fatal error: Using $this when not in object context是说$this只能用于类定义中 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 class SendMail{ /** * smtp parameters * @var array(host, auth, port, username, password) */ var $smtp_param; /** * mail headers * @var array */ var $headers; /** * the body of the mail to be sent * @var string */ var $body; /** * attachment of the mail * @var array */ var $attachment; function connect($host, $username, $pwd){ $class_name = __class__; $object = new $class_name; $object->smtp_param = array( 'host' => $host, 'auth' => true, 'port' => 25, 'username' => $username, 'password' => $pwd ); $this->headers = array(); $this->attachment = array(); return $object; } function setSubject($subject){ $this->headers['Subject'] = $subject; } function setBody($body){ $this->body = $body; } function addAttachment($file){ $this->attachment[] = $file; } function addHeaders($key, $value){ $this->headers[$key] = $value; } function sendTo($recipient){ $mime = new Mail_mime(); //$mime->setTxtBody($this->body); $_ = $mime->setHTMLBody($this->body); if(PEAR::isError($_)){ print($_->getMessage()); return false; } /* if( !empty($this->attachment) ){ foreach( $this->attachment as $_ ){ $r = $mime->addAttachment( $_ ); if( PEAR::isError( $r ) ){ print( $r->getMessage() ); return false; } } } */ //This function should be called once you have added the text/html/images/attachments. //It builds the message and returns it. $body = $mime->get( array ( "text_encoding" => 'base64', "html_encoding" => 'base64', "head_charset" => 'GB2312', "text_charset" => 'GB2312', "html_charset" => 'GB2312' ) ) ; if ( PEAR::isError( $body ) ){ print( $body->getMessage() ); return false; } $headers = $mime->headers( $this->headers ); if ( PEAR::isError( $headers ) ){ print( $headers->getMessage() ); return false; } $mail = Mail::factory( 'smtp', $this->smtp_param ); if ( PEAR::isError( $mail ) ){ print( $mail->getMessage() ); return false; } $a = $mail->send($recipient, $headers, $body); if ( PEAR::isError ( $a ) ){ print( $a->getMessage() ); return false; } return true; }}这是源代码 “$this->headers = array();”这句报错说:Fatal error: Using $this when not in object context 这是 PEAR 的类,不应该有错的请给出完整的错误信息 Fatal error: Using $this when not in object context in /var/www/html/admin/lib/sendmail.class.php on line 61这是完整的错误信息 几个页面在IE9下都会死循环,帮忙看看是怎么回事 用iconv+imagettftext,输出中文字符,哪里错了 memcached取值问题 php 按英文字母a~z排序 100不够再加 刚做的php笔试题,被鄙视了 【急】如何实现 php 服务器端 1个对象(单例模式)的问题! 向高手求两正则表达式!! PHP $_SERVER['DOCUMENT_ROOT'] 问题 淘宝开放平台做一个卖家短信提醒功能应该怎么实现? POST提交同名值时--请进 自写的剪子包袱锤小游戏 有买笔记本的,或者朋友想买电脑的,可以联系一下我,我想把笔记本卖掉。北京的朋友当面交易
/**
* smtp parameters
* @var array(host, auth, port, username, password)
*/
var $smtp_param;
/**
* mail headers
* @var array
*/
var $headers;
/**
* the body of the mail to be sent
* @var string
*/
var $body;
/**
* attachment of the mail
* @var array
*/
var $attachment;
function connect($host, $username, $pwd){
$class_name = __class__;
$object = new $class_name;
$object->smtp_param = array(
'host' => $host,
'auth' => true,
'port' => 25,
'username' => $username,
'password' => $pwd );
$this->headers = array();
$this->attachment = array();
return $object;
}
function setSubject($subject){
$this->headers['Subject'] = $subject;
}
function setBody($body){
$this->body = $body;
}
function addAttachment($file){
$this->attachment[] = $file;
}
function addHeaders($key, $value){
$this->headers[$key] = $value;
}
function sendTo($recipient){
$mime = new Mail_mime();
//$mime->setTxtBody($this->body);
$_ = $mime->setHTMLBody($this->body);
if(PEAR::isError($_)){
print($_->getMessage());
return false;
}
/*
if( !empty($this->attachment) ){
foreach( $this->attachment as $_ ){
$r = $mime->addAttachment( $_ );
if( PEAR::isError( $r ) ){
print( $r->getMessage() );
return false;
}
}
}
*/
//This function should be called once you have added the text/html/images/attachments.
//It builds the message and returns it.
$body = $mime->get( array (
"text_encoding" => 'base64',
"html_encoding" => 'base64',
"head_charset" => 'GB2312',
"text_charset" => 'GB2312',
"html_charset" => 'GB2312' ) ) ;
if ( PEAR::isError( $body ) ){
print( $body->getMessage() );
return false;
}
$headers = $mime->headers( $this->headers );
if ( PEAR::isError( $headers ) ){
print( $headers->getMessage() );
return false;
}
$mail = Mail::factory( 'smtp', $this->smtp_param );
if ( PEAR::isError( $mail ) ){
print( $mail->getMessage() );
return false;
}
$a = $mail->send($recipient, $headers, $body);
if ( PEAR::isError ( $a ) ){
print( $a->getMessage() );
return false;
}
return true;
}
}这是源代码 “$this->headers = array();”这句报错说:Fatal error: Using $this when not in object context