ERROR: Could not instantiate mail function.

ERROR: Could not instantiate mail function.

by Paul Bowers -
Number of replies: 39
When students try to open a new account they are getting this error message. Does anyone know what I need to do?

Thanks, Paul
Average of ratings: -
In reply to Paul Bowers

Re: ERROR: Could not instantiate mail function.

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
What platform are you running on? Have you got your local smtp server properly set up in the administration=>variables screen. If you are running on Windows you will *certainly* need to do this.
In reply to Howard Miller

Re: ERROR: Could not instantiate mail function.

by Marcus Schubert -

I got the same problem. It occcurs when i leaf the smtphost blanck. If i put localhost in this field then there is this error:

Warning: fsockopen(): unable to connect to localhost:25 in C:\Programme\EasyPHP1-7\php\pear\class.smtp.php on line 105
ERROR: SMTP Error: Could not connect to SMTP host.

How can i use localhost as SMTP host?

In reply to Marcus Schubert

Re: ERROR: Could not instantiate mail function.

by Paul Bowers -
yeah marcus, i have the exact same problem and question. i've tried using 'localhost', my ip address, and a thousand other combinations.
i've tried smtp.mail.localhost, mail.localhost, localhost, smtp.mail.myipaddress, mail.myipaddress, myipaddress.
In reply to Paul Bowers

Re: ERROR: Could not instantiate mail function.

by Marcus Schubert -

I searched a little bit and found out that either a firewall blocks the port or the smtp ist not installed correctly in the php.ini.

So i guess i did it right in the php.ini. But is it possible that Apache blcoks this port? I don't know exactly but i tried to access via LAN and the computer that tried to access my IP tried it for a while and then reported page not found.

Can this be an Apache issue? And where can i find if Apache blocks this port?

In reply to Paul Bowers

Re: ERROR: Could not instantiate mail function.

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
You can't just *guess* your SMTP host - you have to know what it is!

If you have Outlook or someother mail client on your machines, what is the SMTP host set to on those? Chances are that it is exactly the same. Do you have a network administrator of some sort to ask?
In reply to Howard Miller

Re: ERROR: Could not instantiate mail function.

by Marcus Schubert -

I thought the phpmailer sends over the localhost. But when i try to send it over localhost i get the error this topic is about.

Isn't "localhost" the SMTP-Host for phpmailer?

If im totally wrong with this, then how can i find the set of outlook?

I guess im little bit too stupid for this wink

In reply to Marcus Schubert

Re: ERROR: Could not instantiate mail function.

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Not stupid - you just don't know it!!

phpmailer (by default) sends using Sendmail which is a Unix/Linux thing - Windows doesn't have this. So, in a windows install you *must* set the SMTP server setting to a valid SMTP server. If your system has one you will know about it because you will have installed it smile

However, if you have outgoing mail working on your network it must be getting sent somewhere - and that somewhere is the SMTP server. But, again, someone must have set this up, so identifying that someone and asking is the easiest route.

I use a Mac and so am not all that familiar with outlook, but basically you are looking for a setup/configuration setting called services. In there you should find the settings for SMTP and POP (or possibly IMAP). You can simply lift the server setting from there. The possible problem is if you use Exchange. In that case you will certainly need to speak to your Exchange administrator.
In reply to Marcus Schubert

Re: ERROR: Could not instantiate mail function.

by Paul Bowers -
found the answer on another thread. type 'qmail' into the smtphost line. worked for me...
In reply to Paul Bowers

Re: ERROR: Could not instantiate mail function.

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
That's weirder than a weird thing - what other thread??


In reply to Howard Miller

Re: ERROR: Could not instantiate mail function.

by Paul Bowers -
found it here:
http://moodle.org/mod/forum/discuss.php?d=4658

however, it's doesn't seem to be fully functioning. it says that the email has been sent, but no email does get sent. ugh!
In reply to Paul Bowers

Re: ERROR: Could not instantiate mail function.

by Marcus Schubert -

I tried qmail too, but if u look in ur Apache logs than u will find that apache doesnt find qmail, so i guess its not installed.

I will try to find it and to install on Apache.

And Howard thanks for ur patience.

I will post up new things i found out.

In reply to Paul Bowers

Re: ERROR: Could not instantiate mail function.

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
We are straying away from the problem here - let's try and get back - and not panic.

I am not sure who here is using Windows and who is using Linux however either way the easiest route is to determine a usable SMTP server on your network. If you are directly connected to the internet it will be your ISP's smtp server - ask them, they will tell you what it is! If it is your own network who set it up? Do you have mail at all on your network?

The 'qmail' thing is a hack for people running on Linux servers with the qmail mail server installed. This probably doesn't apply to you guys. Please don't try and install qmail - it is *very* difficult! Installing any MTA (Mail Transport Agent / Mail Server) is a tricky process requiring some fairly indepth knowledge of Internet technologies and is best avoided!

Most Linux/Unix installations come with Sendmail or some other MTA that emulates it (of which qmail is one example). In that case leaving the smtp setting empty will attempt to send mail using the Sendmail interface. However this will only work if your network is set up correctly so that mail works - so we are back to where we started. Your first step is to either get mail working on your network(s) or identify how they work now - none of this is really a Moodle issue.

Anyway, good luck smile
In reply to Howard Miller

Re: ERROR: Could not instantiate mail function.

by Marcus Schubert -

Hi, im using Windows and trying to send the Mails via LAN. This LAN is not connected to the Internet so i thought it would be a good idea if my WebServer Apache sends the Mails over the LAN.

But i think i understand what u mean - finally wink  The Problem is i got no mail server on my localhost. So i found out, that i got to use Apache James for establishing a mail server.

So as long as im not using Apache James or something like that, the localhost wont send mails. Am i right?

In reply to Marcus Schubert

Re: ERROR: Could not instantiate mail function.

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Yes - and no!

I really want to make sure that you know what you are getting in to, please excuse me in advance if the following is perfectly clear to you...

Apache James is a (open source) Java based mail server - it has nothing to do with the Apache web server excepting that they are both under the same 'banner'. It is a completely separate issue. There are, of course, other MTAs for Windows both commercial/proprietary and open-source.

What you want is something that is often called a 'POP Toaster', that is the server keeps all the local email itself and users access it using the POP3 protocol from their email client (eg, Outlook, Eudora). So James will act as your SMTP server, it will recognise the mail as local and keep it for later collection (by POP3). Any other mail must be sent out to the internet which may well mean forwarding to an external (smtp) server. If you are not connected to the internet the latter does not apply.


In reply to Howard Miller

Re: ERROR: Could not instantiate mail function.

by Marcus Schubert -

Ok, let me resume: I need a programm that uses POP3 as an email client. James would do this. As long as im sending only inside the LAN James does this as SMTP-server.

But if i would use Linux i could use sendmail and all would be easier and php-mailer would work?

If so i better migrate to Linux big grin

In reply to Marcus Schubert

Re: ERROR: Could not instantiate mail function.

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Mail is confusing because it was developed on Unix machines that work nothing like Windows. If you are unfamiliar with Unix then mail protocols seem weird. You just have to get used to that.

Moodle sends - using smtp - mail to the mail server on the same or a different machine. The machine has all the users configured there (there will be some mechanism for this) and stores the mail. The mail machine also needs a POP3 server running so that the actual users can pick up the mail from their remote machines. So you need both protocols running on the mail server. SMTP to accept mail from Moodle (and any other system that needs mail) and POP3 so that users can get it. POP3 involves a username and password so you should expect to have to set up each user on the server somehow.

Depending on the software you choose - this may all be a one-step process or you may have to install individual bits of software for each protocol.

Does this help?

PS. Things would be *much* easier if you used Linux - BUT! In your situation Sendmail wouldn't know what to do with your mail because you have no mail setup on your lan. But (again) it would be reasonable straightforward to set up the machine to act as a mail hub for your users as it is (at least) halfway there.
Attachment maildiag.jpg
In reply to Howard Miller

Re: ERROR: Could not instantiate mail function.

by Marcus Schubert -

Thanks for ur answers, u were a big help. But i guess i test moodle without using its email function at first.

To set up an mail server i guess i choose linux but it seems to take a while to configure it as a mail hub.

Just one last question: If i would use my personal mail account at GMX , then it would be possible to send mails with moodle as long as im online?

Sorry for bothering u with so much questions smile

In reply to Marcus Schubert

Re: ERROR: Could not instantiate mail function.

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
yes - as long as there is a path from the machine that runs moodle to the GMX smtp server. That it, you know the name/address of the GMX smtp server and your Moodle machine can see both the machine and the port (25). I don't know if you have any firewall arrangements that might affect this.
In reply to Howard Miller

Re: ERROR: Could not instantiate mail function.

by Marcus Schubert -
Thank you for helping. Now i know theres no one-click-solution for using this mail function. But i keep trying to set it up in near future
In reply to Marcus Schubert

Re: ERROR: Could not instantiate mail function.

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
...and when you get your Linux box, this is a good place to start:

http://www.qmailrocks.org/
In reply to Howard Miller

Re: ERROR: Could not instantiate mail function.

by Marcus Schubert -
Hi,

i finally got it! I got a nice lil Mail-Server called 'Hamster'. Its Freeware and for windows. And its working fine on my local host. I have only some troubles sending to real email adresses - they dont get delievered.

But i keep fighting Breites Grinsen

Thanks for your help
In reply to Marcus Schubert

Re: ERROR: Could not instantiate mail function.

by Paul Bowers -
yeah, i running on windows as well. i'm also on a lan. shouldn't i be running the mail server from my computer? in that case smtp host would be my ipaddress, correct or not?
In reply to Paul Bowers

Re: ERROR: Could not instantiate mail function.

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
The ip address is that of the machine that is running an SMTP (Mail) server! If it happens to be the same machine as moodle is installed on then it is indeed localhost.

However, note that Windows does not come with a mail server (they want you to buy Exchange). You will know which machine it is because you will have installed the server.

To be honest, my preferred solution would be to dig up an old machine and install a basic linux installation on it to use for mail. Unix/Linux is *much* better at running mail that windows is - but it's still not entirely straightforward.
In reply to Howard Miller

Re: ERROR: Could not instantiate mail function.

by Paul Bowers -
i'd had linux installed on one of my machines before. i partitioned the hard drive and had a dual-boot? system. i have an extra had drive that i can install for such a purpose. which linux would you recommend? i think i used suse before. is there one that would suit my needs better?

thanks for all of your help!
In reply to Paul Bowers

Re: ERROR: Could not instantiate mail function.

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
There are many choices - I like SuSE myself (currently at version 9.2). It has avery good administration interface, Yast, that makes setting it up relatively painless - especially for beginners! 
In reply to Marcus Schubert

Re: ERROR: Could not instantiate mail function.

by Donnie Carpenter -

I have a valid SMTP server specified in my configuration variable and i get this message:


Warning: fsockopen() [function.fsockopen]: unable to connect to mail.templejc.edu:25 (An established connection was aborted by the software in your host machine. ) in C:\Inetpub\wwwroot\moodle\lib\phpmailer\class.smtp.php on line 105
ERROR: SMTP Error: Could not connect to SMTP host.

I saw a reference to this message in this dialog but I'm not clear what the resolution was.. We are attempting to run Moodle 1.5 on a Windows 2003 server.

In reply to Donnie Carpenter

Re: ERROR: Could not instantiate mail function.

by Heather P -

We are using Apache not IIS but are getting something similar. All was well on Moodle 1.5 then we moved to a new server and upgraded to 1.5.2 and now we get the error about connection aborting by host.

Have you managed to crack your problem now and if so what fixed it please? We seem to be going round in circles now.

Thanks

In reply to Heather P

Re: ERROR: Could not instantiate mail function.

by Martín Marqués -
From php.ini

[mail function]
; For Win32 only.
SMTP = localhost

; For Win32 only.
sendmail_from = me@localhost.com

; For Unix only. You may supply arguments as well (default: 'sendmail -t -i').
;sendmail_path =

Configure SMTP to where you have the MTA installed.
In reply to Martín Marqués

Re: ERROR: Could not instantiate mail function.

by Heather P -
Thanks.
Sadly we already had those things configured.
We are on a Windows 2003 Server with Service Pack 1 installed using Apache not IIS. Has anyone got email running on this conguration? We are beginning to think that Port 25 is closed but there is no obvious way (that I can see) to open it.
Desparation approaches - willing to try most things.

Thanks
In reply to Heather P

Re: ERROR: Could not instantiate mail function.

by Eduardo Parra -
Hi! First, I apologize for my bad Englis.guiño
I am running a Windows 2003 Server with Service Pack 1 and Apache.
I have got a problem trying to use send mails from moodle.
Here we go!
Warning: fsockopen(): unable to connect to smtp.ccoo.es:25 in c:\servidor\web\moodle\lib\phpmailer\class.smtp.php on line 105
Could not send you an email to confirm the password change

I used the outlook express with the same configuration that I use in moodle, and I could send and receive.

The mail server is in other machine, and I don't have any clue about what it is going on. I have the antivirus McAffee, if it can help.

Thanks for avance.
In reply to Eduardo Parra

Re: ERROR: Could not instantiate mail function.

by jonathan senior -
I have also replicated my outlook settings in the moodle admin section.
Opened port 26 in my (mcafee) firewall and altered php.ini default mailer to 26 (but moodle should use default if it can;t use 25 right)

All to no avail - strangest thing is that it worked once and then didn;t with no change in settings.

Going to study the email address/envelope for a few clues and post back


In reply to jonathan senior

Re: ERROR: Could not instantiate mail function.

by heinz brandt -
Oh sh ...!!! I´ve to study all this stuff. gedankenverloren
fingerlink
In reply to Eduardo Parra

Re: ERROR: Could not instantiate mail function.

by Jan Spies -
We had the EXACT same problem with the exact same setup and couldn't figure out what was wrong!!

WE FOUND THE PROBLEM!!!

McAfee has its own mini firewall. Open the McAfee virus scan console and disable the port block rule for port 25, thats all!! Took us the best part of 2 weeks disabling everything in Server 2003 trying to figure this out before we realized the only diffs between the new server and the previous one was McAfee.
In reply to Jan Spies

Re: ERROR: Could not instantiate mail function.

by Leang Chumsoben -
Millions thank Jan. The information is really helpful. I also face the same situation but with AVG.
In reply to Leang Chumsoben

Re: ERROR: Could not instantiate mail function.

by Frank Dressler -
Hi all,
I am using Moodle 1.9.7 and the tracker module.
If a create a new issue and store it, i'll get the message: ERROR: Could not instantiate mail function.
The funny thing is, after pressing the continue button all the messages are sent correctly. It's just a little confusing for the normal user getting this error message.

Iam using linux, and the local mail-function, There isn't one of those smtp-entries filled outm, just in the config the entry $CFG->maildomain = 'myDomain.tld'; is set.

Can anybody tell, how to get rid of that error message ?

Thanks Frank

In reply to Frank Dressler

Re: ERROR: Could not instantiate mail function.

by Vagelis Vlachos -

Hello,

I had the same error message, with hosting in hostmonster and using the standard php mail function. After i removed the "No-reply address" from the email configuration  (Administration -> Server -> Email) everything was fine!

Vagelis.

In reply to Vagelis Vlachos

Re: ERROR: Could not instantiate mail function.

by Carlos Lopez -
Thank YOU! I had this problem for months in Hostmonster (Since november) and it was so simple. Thank YOu!
In reply to Carlos Lopez

Re: ERROR: Could not instantiate mail function.

by Rafael Llamas -

Hi Carlos, do you know how to edit the default values for noreplyaddress and supportemail I need to leave it in blank (empty/vacio) in order to solve the email problem related in this topic.

Thanks in advance for your help

Rafael

In reply to Rafael Llamas

Re: ERROR: Could not instantiate mail function.

by Adam Smith -

The solution for me was to edit php.ini as above and remove the noreply address and it sprung into life