我正在尝试使用基于PHP的PEAR库的电子邮件类来工作,但我经常偶然发现这条消息:Fatal error: Call to a member function send() on a non-object in /PATH/email.php on line 42
。我尝试了一些不同的东西,他们还没有在下面的代码中解决问题:
<?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);
上做错了什么(显示错误的地方)?
感谢
答案 0 :(得分:0)
$smtp_conn
的类型是什么?如果工厂失败,它将返回除Mail对象之外的其他内容,例如PEAR :: Error。