0
votes

I am trying to send mail from my component when the user registers. I tried all three i.e PHPMail, Sendmail and SMTP but none works. I am testing it in localhost (WampServer 2.2) and the Joomla version is 2.5.4. I am not sure this is WampServer problem or Joomla or my own code. This is my code:

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;
          }
}       

It gets the error 'could not instantiate mail function'.

2
Wampserver issue most certainly. The code looks correct.McRui
ya i too feel the same. but i don't know which are the settings i need to change in php.ini. i tried changing the smtp value but didn't work. i tried a fresh install of joomla and tried adding the user, i get the same error. so i m 80% sure its wampserver problem.Raaman Rai
oh by the way can u tell me how we have to test smtp server of our ISP. the smtp server i am using in my outlook express is my isp's smtp server and its working, i can send email. i've assigned the same smtp server value in php.ini aswell as in joomla mail settings yet i still have the error in joomla.Raaman Rai

2 Answers

0
votes

i am sure there are many reasons causing this problem. but to test you can always create a mail server of your own by installing this tool here http://www.toolheap.com/test-mail-server-tool/

you don't have to change anything except that you put localhost as the smtp host in joomla mail settings and then in your webserver's php.ini, add the smtp=localhost. thats it, it should work.

this is just to test whether your code is correct and you are using the correct mail settings in joomla. if this doesn't work then, i am sure the problem is not in your code but in your mail settings.

0
votes

To understand what the problem is you really need to get the error message.

Change

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

to

echo 'Error sending email:'.$send->get('message');

then run it again. The error that you get should tell us why it isn't instantiating. Let us know what it says so we can help you out.