Contact Form for Moodle (webmail)

Re: Contact Form for Moodle (webmail)

by Michael Milette -
Number of replies: 6
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators
Hi cyber sec,

Please take a look at the FAQ for Contact Form. I just added a new question which I think might help:
https://github.com/michael-milette/moodle-local_contact/blob/master/README.md#why-isnt-my-form-working

That section also includes information to make Contact Form work with the Static Pages plugin.

Tip - I actually think you are pretty close to getting it working. Assuming your Moodle site is accessed using a URL similar to https://example.com, try changing the line to:

If your Moodle site is in a folder like https://example.com/moodle, you will need to make the action something like /moodle/local/contact/index.php for example. Note that if you have FilterCodes installed, you can just make it {wwwroot}/local/contact/index.php and it won't matter where your instance of Moodle is installed.

Hope you find this useful.

Best regards,

Michael
In reply to Michael Milette

Re: Contact Form for Moodle (webmail)

by cyber sec -
I got this to work on one site, by taking out all the sesskey references.
Now I trying to do the same on another site. On the second site, I am trying to use mydomain@gmail.com to send outgoing email messages.

Gmail works as an outbound mail server in Moodle, but not with the "Contact Form" plugin.

I have created a mydomain@gmail.com account to use for outbound email on Moodle. This works on Moodle, I have ran the outbound mail test, and I have tested student self registration. I have done these tests multiple times, it always works.

But it does not work when using the "Contact Form" plugin. I have put echo statements in sendmail.php to make sure that sendmail.php is being called correctly, and that all the information is correct. But the message is never sent to the mydomain@gmail.com account. This seems odd to me. If Moodle can send outgoing mail using gmail, why does the "Contact Form" plugin not work?


$email=$_POST['email'];
echo "email $email";
$subject=$_POST['subject'];
echo "subject $subject";
$message=$_POST['message'];
echo "message $message";
mail("mydomain@gmail.com", $email ,$subject, $message);
In reply to cyber sec

Re: Contact Form for Moodle (webmail)

by Ken Task -
Picture of Particularly helpful Moodlers

This plugin?

https://moodle.org/plugins/local_contact

"Contact Form is a Moodle plugin that allows your site to process and send information submitted through HTML web forms to the site's support email address or primary administrator if the support email address is not defined."

Sending via a gmail account ... does Google give you any interface into messages that were rejected other than 'spam'?

What if site was setup to use SendGrid (transactional) SMTP relay?

'SoS', Ken

In reply to Ken Task

Re: Contact Form for Moodle (webmail)

by cyber sec -
As far as I can tell, Google does not give me any interface into messages that were rejected other than 'spam'. I checked my spam folder, there is nothing there.

As I see it, the email server setup in Moodle is something like an email client. Except, Moodle is only for outbound.

I took a look at Sendgrid, but I am iffy about their new requirement to have two factor authentication. Moodle provides a method to login with a password, but I am not sure about having to get an message on my cellphone and enter that code.

I am also looking at Amazon SES. Frankly, I am unimpressed with their DKIM requirement. It takes up to three days to verify. If I get anything wrong, I suppose that will take another three days. There is a way around that, using an email address instead of domain name. To use the email address, I guess I am supposed to use their
 "Amazon Resource Name (ARN)" in place of an email server in Moodle. This looks like something else I would have to fight with and try to muddle through. I may, reluctantly, go that route. But, I feel like I am halfway there with gmail, so I am not ready to give up on that just yet.

I reviewed my sendmail.php file. And it looks like I may have some of the parameters out of order. Oddly, this worked before an another website.  I would think the only critical element would be to have the send-to-email in the right place.

Anyway, using this  as my guide:


I rewrote the sendmail.php to more look like this:

$to="mydomain@gmail.com";
echo "to $to";
$subject=$_POST['subject'];
echo "subject $subject ";
$message=$_POST['message'];
echo "message $message";
$from=$_POST['email'];
echo "from $from";
mail($to, $subject, $message, $from);

I could not include the <br> or php tags, but you get the idea.
I I know the sendmail.php file is running.
I know all the parameters are correct.
I am pretty sure the parameters are correctly placed.

But I am still not getting the message in my gmail.com account.


In reply to cyber sec

Re: Contact Form for Moodle (webmail)

by Ken Task -
Picture of Particularly helpful Moodlers

Use Sendgrids API Key with Moodle smtp setup.   That doesn't require 2 factor ... login/pass does.

'iffy' ... well, all I can say is SendGrid is set up to be transactional smtp relay - industrial strength.   A users gmail.com account isn't. smile

My 2 cents, of course.

'SoS', Ken

In reply to Ken Task

Re: Contact Form for Moodle (webmail)

by cyber sec -
I may go back and try Sendgrid again. But, I suspect the problem is: the sendmail.php is not connecting with any email server. I think the issue is with the Contact Form plugin, not the email server. If using gmail as a transactional server did not work, it would not work in Moodle either. But it does work in Moodle, just not with this plugin.

I will try some php exception handling, once I figure out exactly what to do. I suspect that sendmail.php script is looking for a local smtp server, instead of using gmail the way it is setup in Moodle. I may also see if I can find some way to get php to output the smtp server it is trying to use.

In the php.ini file I have this:

[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = localhost
; http://php.net/smtp-port
smtp_port = 25

Moodle, apparently bypasses this. I think the Contact Form plugin is supposed to use the Moodle settings, but for whatever reason, it does not.

I think the problem may be that the Contact Form index.php is not running. It goes right to sendmail.php. This might explain why this worked on my hosted site, but not my VPS site. On the hosted site, the SMTP is local.

In reply to cyber sec

Re: Contact Form for Moodle (webmail)

by cyber sec -
Finally got this to work.
I am now using the suggested "Contact Us" form for a static page.
When I tried this form previously, I kept getting sesskey errors. But now it seems to be working.