Getting blank email content in Pages Mailchannel middleware

Trying out the new MailChannel integration on Pages and I seem to be able to send an email from a form on my site, but when I receive the email it has no body content at all. I am not specifying the ‘content’ array for html/text versions so it should be using the default provided by the plugin as far as I can tell.

Here is the middleware code stored in /functions/_middleware.js (redacted for privacy)

import mailchannelsPlugin from '@cloudflare/pages-plugin-mailchannels'

export const onRequest = mailchannelsPlugin({
  from: { name: '#######', email: '[email protected]#########' },
  personalizations: [
    {
      to: [{ name: '#########', email: '#############' }],
    },
  ],
  respondWith: () =>
    new Response(null, {
      status: 302,
      headers: { Location: '/enquiries/thank-you' },
    }),
  subject: '######### Website Enquiry',
})

form (class attributes removed for brevity)

<form data-static-form-name="contact">
    <div>
        <div>
            <label for="first-name">First name</label>
            <input type="text" name="first-name" id="first-name" autocomplete="given-name"/>
        </div>

        <div>
            <label for="last-name">Last name</label>
            <input type="text" name="last-name" id="last-name" autocomplete="family-name"/>
        </div>

        <div>
            <label for="email-address">Email address</label>
            <input type="text" name="email-address" id="email-address" autocomplete="email"/>
        </div>

        <div>
            <label for="phone">Phone</label>
            <input type="text" name="phone" id="phone" autocomplete="phone"/>
        </div>
        <div>
            <label for="message">Message</label>
            <textarea id="message" name="message" rows="4"/>
        </div>
    </div>
    <div>
        <button type="submit">Send Enquiry</button>
    </div>
</form>

Any help would be appreciated.

I am having the exact same problem and my code looks very similar to yours. What’s even more bizarre is that mine was working a few weeks ago. My code hasn’t changed at all.

Looks like this was resolved and was due to the following issues maybe.

From Ken Simpson at Mailchannels support

I think what’s happening here is that Cloudflare has added some new IPs to the Workers service and we need to update our records to allow connections from them. We will do that. This should be resolved soon.

Anyway I just tested it and it is working again.

1 Like