根据Joomla!文档@http://docs.joomla.org/Sending_email_from_extensions,我尝试使用以下代码发送电子邮件:
function sendmail($file,$mailto)
{
$mailer =& JFactory::getMailer();
//var_dump($mailer); exit;
$config =&JFactory::getConfig();
$sender = array(
$config->getValue( 'config.mailfrom' ),
$config->getValue( 'config.fromname' )
);
$mailer->setSender($sender);
$recipient = array($mailto);
$mailer->addRecipient($recipient);
$body = "Your body string\nin double quotes if you want to parse the \nnewlines etc";
$mailer->setSubject('Your subject string');
$mailer->setBody($body);
// Optional file attached
$mailer->addAttachment(JPATH_BASE.DS.'CSV'.DS.$file);
$send =&$mailer->Send();
if ( $send !== true ) {
echo 'Error sending email: ' . $send->message;
} else {
echo 'Mail sent';
}
}
($file
是 zip 文件的完整路径,$mailto
是我的 gmail 地址。)
然而,当我发送邮件时,我收到以下错误提示:
无法实例化邮件函数。
致命错误: 在 /var/www/html/dai/components/com_servicemanager/views/i0602/view.html.php 的第142行中无法访问受保护的属性 JException::$message
是什么导致了这个错误?