无法在joomla 2.5.4中实例化邮件功能

时间:2013-02-02 13:11:42

标签: joomla phpmyadmin joomla2.5 php

我正在尝试在用户注册时从我的组件发送邮件。我尝试了所有这三个,即PHPMail,Sendmail和SMTP,但都没有。我在localhost(WampServer 2.2)中测试它,Joomla版本是2.5.4。我不确定这是WampServer问题还是Joomla或我自己的代码。这是我的代码:

function postmail($name, $receiver){

          jimport('joomla.mail.helper');

          $mailer =& JFactory::getMailer();

          $config =& JFactory::getConfig();
          $sender = array($config->getValue( 'config.mailfrom'),$config->getValue( 'config.fromname' ) );
          $mailer->setSender($sender);

          $recipient = $receiver;
          $mailer->addRecipient($recipient);

          $body   = "<body><br><p>"; 
          $body   .= "<strong>$name,</strong>&nbsp;";   
          $body   .= "</p><br></body>";

          $mailer->isHTML(true);
          $mailer->Encoding = 'base64';
          $mailer->setBody($body);

          $send =& $mailer->Send();

          if ( $send != true ) {
                    //echo 'Error sending email: ' . $send->message;
            return false;
          } else {
                    //echo 'Mail sent';
                return true;
          }
}       

它收到错误'无法实例化邮件功能'。

2 个答案:

答案 0 :(得分:0)

我确信导致此问题的原因有很多。但要测试,您可以通过在http://www.toolheap.com/test-mail-server-tool/

安装此工具来创建自己的邮件服务器

除了将localhost作为gamp邮件设置中的smtp主机,然后在web服务器的php.ini中添加smtp = localhost之外,您不必更改任何内容。这就是它,它应该工作。

这只是为了测试您的代码是否正确以及您是否在joomla中使用正确的邮件设置。如果这不起作用,我确信问题不在您的代码中,而是在您的邮件设置中。

答案 1 :(得分:0)

要了解问题是什么,您确实需要获取错误消息。

更改

//echo 'Error sending email: ' . $send->message;

echo 'Error sending email:'.$send->get('message');
然后再次运行它。你得到的错误应该告诉我们为什么它没有实例化。让我们知道它的内容,以便我们为您提供帮助。

相关问题