So, i decided to give Machform a spin on a project i was working on. Figured it would be quick and easy to get up and running. It was — locally — but when deploying to my sandbox/staging server, i ran into issues with sending notification emails. It was maddening. Spent a couple of days getting everything working as needed and on the same page for all three differing environments.
The first problem occurred when submitting the form: no notification on-page would show up — it just was a blank area. After much futzing around, looking at logs and such, i decided to start from scratch with a new form, using default options to see what happened:
- Default, basic form worked as expected, showing a success message on-page
- No email notifications set in the “Notifications” options
- Even though the email notifications weren’t firing off on the original form i noticed the problem on, the submissions did actually get propagated to the database — for both my “complicated” and simple, default form. So i knew it had to be an issue with email sending, specifically.
More research: i ran phpinfo on my localhost configuration, the staging/sandbox server, as well as the production server to compare their setups. They looked identical, but further tests i discovered that non-local servers didn’t have sendmail installed. I figured that out by running some PHP code. Use out the gist below, if you’d like to test on your own server.
Here are the things i checked/did while figuring out what was wrong. Also, be sure to restart Apache or nginx after each install to see what fixes the issue. And notice that the terminal commands might be slightly different if you’re running an Apache server vs nginx. This was a point of annoyance for me being that for some reason our staging and production servers weren’t setup identically — something i’ll have to address with the powers that be that originally setup the servers. But that’s neither here nor there for this piece.
- If sendmail is installed,
- Use the gist above to test if you can use mail() to send email
- Run this to install sendmail, configure it (follow prompts), then create and grant necessary ownership to log files:
sudo apt-get install sendmail sudo sendmailconfig sudo touch /var/log/mail.log /var/log/mail.err sudo chown syslog:adm /var/log/mail.log /var/log/mail.err
- Now, we need to edit the /etc/hosts file with hostnames, local to your computer or the server then the actual server’s hostname.server like so (run command hostname to get the hostname):
127.0.0.1 localhost.localdomain localhost 0.0.0.0 ip-0.0-0-0-0.yourdomainnamehere.com ip-0-0-0-0
- Run this to install mbstring:
-
sudo apt-get install php-7.*mbstring
-
- Install php-xml to fix the PDF issue if above mbstring is already installed:
- Run
sudo apt-get install php-xml
- Run
After all of this is installed, Machform should be start to be able to send email notifications. Still running into nginx not sending PDFs, but at least it’s not breaking form submissions; emails get sent, but only with attached images, and no PDF with all the data. It’s odd.
Be sure to keep an eye out on the log files, specifically /var/log/mail.log and /var/log/mail.err
I hope this helps! Get in the comments if you have any questions. Or, send me something on Twitter — @CaptMacSparrow.
Cheers.
[Update 2018.08.21] So, after more digging and issues, i realized that the real slowness culprit was with Gmail! In one of the mail logs, i noticed this portion “verify=FAIL” all throughout when attempting to send mail. I hadn’t set a username/password in System Settings -> “Use SMTP Server to Send Emails” option. Silly me.
Suffice it to say, i had to scour through more Google documentation, message boards, etc., but i came up with a solution for going from 1.5-2 minutes to submit form and get email to send, down to under 20 seconds!
Here’s what you need to do:
- Have a valid gmail/g suite email account with user and password
- Use those credentials for smtp.gmail.com, setting TLS and port 587
- Setup 2-Step Verification for the gmail account
- Attempt to submit a Machform from your site — this should cause Google to alert that a “less secure app” is attempting to login with your account.
- You’ll then need to setup an “app password”. See screenshots below this bullet list.
- Now, once you have the app password, make sure you use that new password that is strictly for the app in your Machform settings.
- Test the form again, and voila! You should be all set.
I hope that helped you out as it did me. So, basically for SEO purposes: this post update should help with a slow Machform submission using a Gmail or G Suite email address via php mail/sendmail. Machform not sending email, this is for you!
Cheers!