Trouble setting up email in 2.6 on Hostmonster

Trouble setting up email in 2.6 on Hostmonster

by Michael Usavage -
Number of replies: 23

Hello,

I've been having a very tough time getting my 2.6 (Version 2013111801.11) install of Moodle to be able to send out emails. The install is currently hosted at Hostmonster and was installed through the Mojo Marketplace. I know this isn't a preferred set up, but I needed something easy because this is my first time using Moodle, and I'm a beginner-intermediate Linux admin.

Anyway, everything is working well except for sending emails out of the system. On the Site administration > Plugins > Message outputs > Email page, I've tried a number of configurations that include: using a verified, working hostmonster based email account, using the phpmailer built into Moodle, and Gmail SMTP. I've recreated the settings I tried for the hostmonster and phpmailer attempts:

Hostmonster email:

SMTP hosts: host413.hostmonster.com:465

SMTP security: SSL

SMTP username: mailer@domainx.com

SMTP password: *********

SMTP session limit: 1

No-reply address: mailer@domainx.com

Character set: UTF-8

Allow user to select character set: No 

Allow attachments: Yes

Newline characters in mail: LF

 

PHP Mailer:

SMTP hosts: 

SMTP security: 

SMTP username: 

SMTP password:

SMTP session limit: 1

No-reply address: mailer@domainx.com

Character set: UTF-8

Allow user to select character set: No 

Allow attachments: Yes

Newline characters in mail: LF

 

With these two set ups, I have never received email messages from the system for password resets or logged out messaging. Do the settings I entered appear to be immediately wrong? I've also tried manually editing the php files for the smtp and phpmailer libs with the email settings, but that didn't do anything, so I reverted back to the stock copies. Cron is also set up and running with the following command: wget -q -O /dev/null http://subdomainx.domainx.com/admin/cron.php. When I go to the link, I see the cron page run.

Does anyone have any ideas or advice for my problem? How can I grab an error log from Moodle to see what's going on in the background?

Thanks in advance.

 

 

  

Average of ratings: -
In reply to Michael Usavage

Re: Trouble setting up email in 2.6 on Hostmonster

by Floyd Saner -

Michael,

The first thing I would check is whether or not a CRON job has been set up.  That is what processes email, among other things related to Moodle.

http://docs.moodle.org/22/en/Cron

Floyd

In reply to Floyd Saner

Re: Trouble setting up email in 2.6 on Hostmonster

by Michael Usavage -

I set cron up in Cpanel. When I go to the URL inside of the command, it runs the cron process. I've tried visiting the cron page immediately after sending an email in Moodle, but nothing happens.

In reply to Michael Usavage

Re: Trouble setting up email in 2.6 on Hostmonster

by Floyd Saner -

Ah, there are two cron scripts - one to be run from a browser and one to be executed by php in a scheduled CRON.  Documentation is copied below.  Note that the command line script is located in a different folder than the web-based script.  Most CRON user interfaces have a way to send an email each time the job runs.  Try adding that feature until you are certain the scheduled CRON is running.

Working out the Moodle cron command

Moodle has two different ways to deploy cron which use different scripts within the Moodle install. These are as follows...

  1. The CLI (command line interpreter) script. This will be at the path
    /path/to/moodle/admin/cli/cron.php
    If in doubt, this is the correct script to use. This needs to be run by a 'PHP CLI' program on your computer. So the final command may look something like
    /usr/bin/php /path/to/moodle/admin/cli/cron.php
    You can (and should) try this on your command line to see if it works.

  2. The web based script. This needs to be run from a web browser and will be accessed via a web url something like http://your.moodle.site/admin/cron.php. You can find command line based web browser (e.g. wget) so the final command may look like
    /usr/bin/wget http://your.moodle.site/admin/cron.php
Average of ratings: Useful (1)
In reply to Floyd Saner

Re: Trouble setting up email in 2.6 on Hostmonster

by Michael Usavage -

I was originally using the wget command in cpanel. I switched that out to /usr/bin/php /path/to/moodle/admin/cli/cron.php. I haven't gotten any email alerts with output from the job.

I'll try to run the command from the CLI next.

In reply to Michael Usavage

Re: Trouble setting up email in 2.6 on Hostmonster

by Floyd Saner -

Check Hostmonster's documentation on CRON command setup.  Different host companies have different setups.  For example,

one host I use requires 

  /usr/php/54/usr/bin/php /home/root_dir/public_html/moodle/admin/cli/cron.php

another host I use requires

  php /home/root_dir/public_html/moodle/admin/cli/cron.php

Ah, looks like Hostmonster just requires php, see https://my.hostmonster.com/cgi/help/168

Average of ratings: Useful (1)
In reply to Floyd Saner

Re: Trouble setting up email in 2.6 on Hostmonster

by Michael Usavage -

I have two cron's in place now based off of the hostmonster support page:

1. /usr/bin/GET /path/to/moodle/admin/cron.php 

2. php /path/to/moodle/admin/cli/cron.php

Number 1 is basically what I already had running before. Is one preferred over the other?

Regardless, I've been getting successful cron run emails from hostmonster for script 1, but emails still aren't coming through. 

In reply to Michael Usavage

Re: Trouble setting up email in 2.6 on Hostmonster

by Floyd Saner -

Michael,

Either CRON command should work.  I usually use the PHP command, but don't have any real reason for doing that.  Perhaps someone else can provide reason for one over the other.

Now that CRON is running, and it seems the default PHP email is running (I think that is what Hostmonster uses to send out your CRON message), I suggest going back to the Moodle system admin email settings and try the default PHP email settings.  Be certain each field has the default value.  Send an email and see what happens.  You will have to wait until CRON runs.

If you don't receive an email, check your CRON report.  If the problem is on the Moodle side, you should see an error message in the report.  If Moodle is OK, then check your email SPAM filter, the Hostmonster error log and your server MX records.

Report back on your findings.

Floyd

In reply to Floyd Saner

Re: Trouble setting up email in 2.6 on Hostmonster

by Michael Usavage -

I reset all settings back to to the default. I got an email saying that cron ran successfully and gave me the following output:

Created missing context instances
Running session gc tasks...
...finished stale session cleanup
Running auth crons if required...
... started 13:15:02. Current memory use 16.4MB.
Running enrol crons if required...
Running cron for enrol_manual...
... started 13:15:02. Current memory use 17.1MB.
Verifying manual enrolment expiration...
...manual enrolment updates finished.
manual enrolment expiry notifications were already sent today at Sunday, 9 March 2014, 6:00 AM.
Running cron for enrol_self...
... started 13:15:02. Current memory use 17.3MB.
Verifying self-enrolments...
...user self-enrolment updates finished.
No expired enrol_self enrolments detected
self enrolment expiry notifications were already sent today at Sunday, 9 March 2014, 6:00 AM.
Running cron for enrol_cohort...
... started 13:15:02. Current memory use 17.3MB.
Starting activity modules
Processing module function assign_cron ...... started 13:15:02. Current memory use 18.6MB.
... used 1 dbqueries
... used 0.39305686950684 seconds
done.
Processing module function chat_cron ...... started 13:15:03. Current memory use 27.4MB.
... used 5 dbqueries
... used 0.0052978992462158 seconds
done.
Processing module function forum_cron ...... started 13:15:03. Current memory use 29MB.
Starting digest processing...
Cleaned old digest records
... used 4 dbqueries
... used 0.0061328411102295 seconds
done.
Processing module function quiz_cron ...... started 13:15:03. Current memory use 29.3MB.

Looking for quiz overdue quiz attempts...
Considered 0 attempts in 0 quizzes.
Starting quiz reports
Finished quiz reports
... used 2 dbqueries
... used 0.19391298294067 seconds
done.
Processing module function scorm_cron ...... started 13:15:03. Current memory use 33.4MB.
... used 1 dbqueries
... used 0.014402151107788 seconds
done.
Processing module function workshop_cron ...... started 13:15:03. Current memory use 34.1MB.
processing workshop subplugins ...
Starting workshop allocation methods
Processing cron function for workshopallocation_scheduled...
... started 13:15:03. Current memory use 35.1MB.
... no workshops awaiting scheduled allocation. done. (1 dbqueries, 0 seconds)
Finished workshop allocation methods
... used 6 dbqueries
... used 0.022149085998535 seconds
done.
Finished activity modules
Starting blocks
Processing cron function for rss_client....... started 13:15:03. Current memory use 35.3MB.

0 feeds refreshed (took 0.00030600000000003 seconds)
done.
Finished blocks
Starting admin reports
Finished admin reports
Starting main gradebook job...
... started 13:15:03. Current memory use 36.5MB.
done.
Starting processing the event queue...
... started 13:15:03. Current memory use 36.5MB.
done.
Starting course reports
Finished course reports
Starting gradebook plugins
Finished gradebook plugins
Updating calendar subscriptions:
... started 13:15:03. Current memory use 38.7MB.
Finished updating calendar subscriptions.
Fetching external blog entries...... started 13:15:03. Current memory use 39.1MB.
done.
Deleting blog associations linked to non-existent contexts...... started 13:15:03. Current memory use 39.1MB.
done.
Starting the question bank cron...... started 13:15:03. Current memory use 39.1MB.

Cleaning up old question previews...done.

Cleaning up old question statistics cache records...done.
done.
Starting registration update on hubs...
... started 13:15:03. Current memory use 39.3MB.
Finished registration update on hubs.
Recently fetched info about available updates is still fresh enough, skipping.
Deleting session linked tokens more than one day old...... started 13:15:03. Current memory use 39.5MB.
done.
Starting repository plugins
Processing cron function for repository_dropbox...
... started 13:15:04. Current memory use 45.6MB.
done. (1 dbqueries, 0 seconds)
Processing cron function for repository_filesystem...
... started 13:15:04. Current memory use 45.6MB.
done. (3 dbqueries, 0 seconds)
Finished repository plugins
Starting admin tools
Processing cron function for tool_qeupgradehelper...
... started 13:15:04. Current memory use 45.8MB.
done. (0 dbqueries, 0 seconds)
Finished admin tools
Running cache cron routines
Cleaning up stale session data from cache stores.
done.
Checking automated backup status...INACTIVE
Starting badges cron...
Started reviewing available badges.
Badges were issued 0 time(s).
Sending scheduled badge notifications.
done.
Deleting old draft files... ... started 13:15:04. Current memory use 49.5MB.
done.
Deleting orphaned preview files... ... started 13:15:04. Current memory use 49.5MB.
done.
Cron script completed correctly
Cron completed at 13:15:04. Memory used 49.5MB.
Execution took 2.098122 seconds

 

After checking the error logs, I noticed the following:

 

[09-Mar-2014 08:05:02] PHP Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /home1/username/public_html/sitefolder/admin/cron.php on line 56

[09-Mar-2014 08:05:02] PHP Parse error: syntax error, unexpected T_STRING in /home1/username/public_html/sitefolder/admin/cron.php on line 56

and

[08-Mar-2014 16:00:01] PHP Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /home1/username/public_html/sitefolder/lib/setup.php on line 779

[08-Mar-2014 16:00:01] PHP Parse error: syntax error, unexpected T_STRING in /home1/username/public_html/sitefolder/lib/setup.php on line 779

 

It seems to be repeating every 5 minutes.

 
In reply to Michael Usavage

Re: Trouble setting up email in 2.6 on Hostmonster

by Floyd Saner -

For now, I would forget about the error log messages - they are only warnings.

I did not see anything in the cron message that indicated emails were being processed.  Were some messages waiting to be processed?

I would try posting a message in a course News Forum and select the 'mail now' option.  Be certain at least one person is registered as a student in the course and you have access to the email accounts for that student.  If you have email self-registration enabled, you can also try to register someone and see if an email is sent to the address provided.

If you are expecting emails from discussion forums, you should be aware that any user whose profile is configured for email digests will not receive subscribed forum posts until after the digest time setting in the site admin section.

Floyd

In reply to Floyd Saner

Re: Trouble setting up email in 2.6 on Hostmonster

by Michael Usavage -

The two tests I was doing were password reset emails and sending message to a user who is offline and has email response selected. I'll try your suggestions as well.

In reply to Floyd Saner

Re: Trouble setting up email in 2.6 on Hostmonster

by Floyd Saner -

Michael,

You might also try the following to take Moodle out of the equation and test your PHP mail service.

  1. Create a text file with the php code shown below.  Save the file as emailtest.php and place it in your server's public_html folder.

  2. Place the following in your browser address bar:  http://your_web_server_address.com/emailtest.php and press enter.  You will want to replace your_web_server_address.com with your actual server address.  You can also just execute the file emailtest.php from a command line interface.

  3. You should receive an email in a short time.  This does not rely on the Moodle cron job.  If you don't receive an email, then some server or php settings are not correct.

  4. Remove the file from your server after successful testing.

 

// php code to test mail service
// be certain to replace 'youremail@someservice.com' with your own email address - must be in single quotes
<?php 

$to = 'youremail@someservice.com'; 
$subject = 'Test email using PHP'; 
$message = 'This is a test email message'; 
$headers = 'From: webmaster@example.com' . "\r\n" . 'Reply-To: webmaster@example.com' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); 
mail($to, $subject, $message, $headers); 
?>

In reply to Floyd Saner

Re: Trouble setting up email in 2.6 on Hostmonster

by Michael Usavage -

The emailtest.php worked immediately. 

In reply to Michael Usavage

Re: Trouble setting up email in 2.6 on Hostmonster

by Floyd Saner -

Great! That is good news!  If you use the default php email setup in Moodle, then Moodle does essentially the same thing that short file did. Moodle runs php code that sends out emails.  So if email worked with that short test file, I believe Moodle should be able to send email as long as Moodle is configured properly.  I'm open to any suggestions otherwise.

I'm certain you have checked and re-checked Moodle's mail configuration settings.  But I know I overlook things sometimes. So go back and be certain the SMTP hosts field is totally empty - no spaces, no tiny periods, etc., and save changes.

If you still have problems, check your Messages settings.

I'm beginning to run out of ideas.  Anyone else care to jump in?

Floyd

In reply to Michael Usavage

Re: Trouble setting up email in 2.6 on Hostmonster

by Floyd Saner -

Michael,

Just a couple more thoughts here. It is critical to isolate the problem to either Moodle or to your HostMoster configuration.  You have established that simple PHP email processing does work.  I'm baffled by the failure of Moodle to send email using that configuration.  Ammar has a good suggestion about SMTP email.  You might want to call HostMonster support and talk with them.

Just a couple questions:

  1. Is it true that you have tried both PHP and SMTP mail settings in Moodle and neither one works for you?
  2. Are you able to send and receive email outside of Moodle with the HostMonster SMTP mail account you are using?

I'll contact you privately about some other options.

In reply to Michael Usavage

Re: Trouble setting up email in 2.6 on Hostmonster

by Leandro Gurruchaga -

Hi Michael:

Can you tell me the final syntax to execute succesfully the cron job in hostmonster ?

I'm getting error for the execution.


Thanks !

In reply to Leandro Gurruchaga

Re: Trouble setting up email in 2.6 on Hostmonster

by Usman Asar -
Picture of Plugin developers Picture of Testers

Rita, hijacking old threads sometimes leads to ignored questions. If you see some thread that you want to ask questions related to, and that thread is few months old, its always better starting a new thread. but anyway, regarding your query, use this in CRON section of HostMonster or any CPanel based hosting provider

php -q /home/hostmonsteraccount/public_html/mymoodle/admin/cli/cron.php


Where I mentioned hostmonsteraccount = you will be providing your username assigned to you by hostmonster shared hosting

and where I mentioned mymoodle = you will be providing absolute path to your moodle directory.

In reply to Usman Asar

Re: Trouble setting up email in 2.6 on Hostmonster

by Leandro Gurruchaga -

Thanks Usman.

The cron is executing, but with a warning and an parse php error in setup.php:


[08-Apr-2016 15:37:01] PHP Warning:  Unexpected character in input:  '\' (ASCII=92) state=1 in /home1/myaccount/public_html/moodle/lib/setup.php on line 785

[08-Apr-2016 15:37:01] PHP Parse error:  syntax error, unexpected T_STRING in /home1/
myaccount/public_html/moodle/lib/setup.php on line 785
viewing setup.php i d'ont found where is the error.


In reply to Leandro Gurruchaga

Re: Trouble setting up email in 2.6 on Hostmonster

by Usman Asar -
Picture of Plugin developers Picture of Testers

Rita, have you installed Moodle manually or through their MOJO script installer?

also, this output is coming from CLI based auto run command, have you tried running cron manually? giving same errors?

In reply to Usman Asar

Re: Trouble setting up email in 2.6 on Hostmonster

by Leandro Gurruchaga -

Hi Usman:

- the installation was manually

I didn't try the execution manually, only in a cron job. 


In reply to Leandro Gurruchaga

Re: Trouble setting up email in 2.6 on Hostmonster

by Usman Asar -
Picture of Plugin developers Picture of Testers

Try a manual run of CRON through web interface and see if this works fine, else open up a new forum post with your CRON output error.

In reply to Usman Asar

Re: Trouble setting up email in 2.6 on Hostmonster

by Leandro Gurruchaga -

The cronjob is ok through web interface.

I'll open a new thread. Thanks !

In reply to Michael Usavage

Re: Trouble setting up email in 2.6 on Hostmonster

by Tony Hendrix -

Michael, did this ever get resolved? I'm thinking of abandoning HostMonster if i can't get emails to come from Moodle.