Submission-Created not executing on form submission

Hey there,

I set up a simple function to send an email when a form containing only an email field is submitted. It worked great so I left it alone. I’ve now noticed that emails that were submitted didn’t receive the email, upon further investigation, that functionality is no longer working for new form submissions.

I’ve created a duplicate function to call manually through postman and it executes fine. Additionally, no logs show up for the submission-created function. It looks like it simply isn’t executing, but the form submissions are showing up in the forms tab.

Any idea what could be going?

Netlify instance is lifemetrics.io

Update:

I just tested this on another site I had running, wumbohere.com, wumbo.netlify.com
Submissions through forms are not working on there either, even though they were just the other day.

It appears that some of the form submissions are being executed now, many minutes (maybe hours) later.

Is Netlify experiencing some issue with this service at the moment? Does this functionality not have a reliable time to execution? Is it throttled for starter plan users?

Hi!
I also have a cloud function that runs on form submission.
Yes, it appears that it sometimes can take some time (for me about 5-10 minutes) before both services, Netlify Forms + Netlify Functions, finish their jobs.
In my case, that delay is not an issue.
In my opinion, the plan doesn’t make a difference (I’m on the PRO plan).

Hey, thanks for the reply.

Unfortunate that the PRO plan doesn’t help.

They should include the expected time to execution or some kind of disclaimer as part of their documentation.

While we don’t provide guarantees on how long it takes for that function to fire, it should be firing off immdiately when we receive the submission. There would really only be a delay if there was unusually high load. Can you provide an example of a specific form submission that did not fire off the function immediately? This would be easier than digging through all submissions to try and find one that took several minutes to fire.

Hi! Thanks for the detailed reply :smiley:
Actually, the serverless function does fire immediately after the form has been successfully submitted. Only the Netlify form can sometimes take up to several minutes before the submission appears in the Netlify UI dashboard.
(But like I said, this not an issue for me :wink:)

I have this same issue, but my function doesn’t trigger even hours after the form is submitted.

The form submits fine - I can see the submission in the dashboard; but the function doesn’t execute and the log stays blank.

I’ve tried building the function differently (netlify-lambda vs zip-it-and-ship-it) to no avail.

Here’s the site (speaking of which, it redirects to an un-styled 404 page in Chrome, but works fine in Firefox - separate issue, I know).

I’d appreciate any help! Thanks :slight_smile:

Hey @asher,
Would you mind sharing your function code? I just tested a submission-created function on a personal site and it worked as expected, so I’m wondering if something in your code is failing silently. Thanks!

Hi @jen-

Here you go:

submission-created.js
const juice = require('juice');
const nunjucks = require('nunjucks');
const nodemailer = require('nodemailer');

const emailTemplate = nunjucks.compile( *valid nunjucks template, left out for simplicity* );

exports.handler = async (event, context) => {
  console.log("function run");
  let sendData = JSON.parse(event.body).data;
  const { ADDRESS_TO, SMTP_USER, SMTP_PASS } = process.env;

  let messageHTML = juice(nunjucks.render(emailTemplate, sendData));

  let transporter = nodemailer.createTransport({
    host: "smtp.mailtrap.io",
    port: 2525,
    auth: {
      user: SMTP_USER,
      pass: SMTP_PASS
    }
  });

  let message = {
    from: 'from@smtp.mailtrap.io',
    to: ADDRESS_TO,
    subject: `[Contact Form] ${sendData.name}: ${sendData.subject}`,
    text: `"${sendData.name}" <${sendData.email}> wrote:\n\n---${sendData.subject}---\n\n${sendData.message}`,
    html: messageHTML
  };

  let info = await transporter.sendMail(message);

  return {
    statusCode: 200,
    body: JSON.stringify(info)
  }
}

I’m using netlify-lambda for the build step, but thinking of switching to a custom webpack setup.

Hmmm something is definitely broken here! Our logs are showing that we silently return a 502 Bad Gateway error when your function is called. This is not the case when I test my function, so it’s not a systemic functions issue. To narrow things down further, could you replace your code with a super simple function like:

exports.handler = async function(event, context) {
    console.log(JSON.parse(event.body))
    return {
      statusCode: 200,
      body: event.body
    };
};

and see if it logs for you or continues to show nothing here https://app.netlify.com/sites/geistmaschine/functions/submission-created when you submit a form?

well, first you should try adding the word function here after async:

exports.handler = async (event, context) => {

and if that doesn’t work, plan B is the super simple function :slight_smile: