无法在joomla 2.5.4中实例化邮件函数

无法在joomla 2.5.4中实例化邮件函数,joomla,phpmyadmin,joomla2.5,php,Joomla,Phpmyadmin,Joomla2.5,Php,当用户注册时,我正在尝试从我的组件发送邮件。我尝试了所有三种方式,即PHPMail、Sendmail和SMTP,但都不起作用。我正在本地主机(WAMPServer2.2)中测试它,Joomla版本是2.5.4。我不确定这是WampServer问题还是Joomla或我自己的代码。这是我的代码: function postmail($name, $receiver){ jimport('joomla.mail.helper'); $mailer =&

当用户注册时,我正在尝试从我的组件发送邮件。我尝试了所有三种方式,即PHPMail、Sendmail和SMTP,但都不起作用。我正在本地主机(WAMPServer2.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;
          }
}       
函数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=$recipient;
$mailer->addRecipient($recipient);
$body=“
”; $body.=“$name,”; $body.=“


”; $mailer->isHTML(true); $mailer->Encoding='base64'; $mailer->setBody($body); $send=&$mailer->send(); 如果($send!=true){ //回显“发送电子邮件时出错:”。$send->message; 返回false; }否则{ //回显“已发送邮件”; 返回true; } }

它收到错误“无法实例化邮件函数”。

我确信有很多原因导致此问题。但是为了测试,您可以通过在此处安装此工具来创建自己的邮件服务器

您无需更改任何内容,只需在joomla邮件设置中将localhost作为smtp主机,然后在Web服务器的php.ini中添加smtp=localhost。就这样,它应该会起作用


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

要了解问题所在,您确实需要获取错误消息

改变

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


然后再运行一次。您得到的错误应该告诉我们为什么它没有实例化。让我们知道它说了什么,这样我们就可以帮助您。

Wampserver问题肯定会出现。代码看起来是正确的。是的,我也有同样的感觉。但是我不知道我需要在php.ini中更改哪些设置。我尝试更改smtp值,但没有成功。我尝试了joomla的新安装,并尝试添加用户,我得到了相同的错误。所以我80%肯定它的wampserver问题。哦,顺便问一下,你能告诉我我们如何测试我们ISP的smtp服务器吗。我在outlook express中使用的smtp服务器是我的isp的smtp服务器,我可以发送电子邮件。我已经在php.ini和joomla邮件设置中分配了相同的smtp服务器值,但joomla中仍然存在错误。
echo 'Error sending email:'.$send->get('message');