0
我試圖讓一個基於PHP的PEAR庫的電子郵件類工作,但我不斷碰到這條消息:Fatal error: Call to a member function send() on a non-object in /PATH/email.php on line 42
。我已經嘗試了一些不同的事情,他們並沒有解決下面的代碼的問題:與基於PEAR的電子郵件類錯誤
<?php
require_once 'Mail.php';
require_once './config/config.php';
class Email
{
var $smtp_host;
var $smtp_port;
var $smtp_user;
var $smtp_pass;
var $from;
var $smtp_conn;
function Email($init_smtp_host=SMTP_HOST, $init_smtp_port=SMTP_PORT, $init_smtp_user=SMTP_USER, $init_smtp_pass=SMTP_PASS, $init_from_name='admin', $init_from_email=SMTP_USER)
{
$smtp_host = $init_smtp_host;
$smtp_port = $init_smtp_port;
$smtp_user = $init_smtp_user;
$smtp_pass = $init_smtp_pass;
$from = $init_from_name . ' <' . $init_from_email . '>';
$smtp_conn =& Mail::factory('smtp',
array( 'host' => $this->smtp_host,
'port' => $this->smtp_port,
'auth' => TRUE,
'username' => $this->smtp_user,
'password' => $this->smtp_pass));
}
function send($to_name, $to_email, $subject, $message)
{
$to = $to_name . ' <' . $to_email . '>';
$header = array('From' => $this->from, 'To' => $to, 'Subject' => $subject);
$mail = $this->smtp_conn->send($to, $header, $message);
if (PEAR::isError($mail))
return $mail->getMessage();
else
return 0;
}
}
我做得不對的$mail = $this->smtp_conn->send($to, $header, $message);
(其中正在顯示錯誤)? 謝謝
調用`$ smtp_host = ...`實際上並沒有設置你的類'字段,你需要執行`$ this-> smtp_host = ...' – 2011-02-03 02:54:50
這解決了我的問題。非常感謝你。 – nickles 2011-02-03 03:15:41