Skip to content

Emailing

Drew Baker edited this page Apr 25, 2021 · 1 revision

The backend theme includes a sendEmail mutation. Simply uncomment gql_register_email_mutation action in /functions/gql-functions.php. I'd recommend hard coding the to email address in this function is possible.

The mutation maps to the wp_mail() function, so please read that for a description of required inputs.

The mutation comes with a basic form of anti-spam protection. The input trap must equal the same as the clientMutationId. With GraphQL, the clientMutationId is a unique identify and you can set it to whatever you like.

The Log Emails plugin is handy to install, to track what emails are getting sent. You can get it here.

So for example:

mutation MyMutation {
  sendEmail(
      input: {
          clientMutationId: "12345",
          to: ["[email protected]"],
          message: "Email body here",
          subject: "Subject text here",
          trap: "12345",
          headers: ["From: [email protected]"] # Will default to WordPress@{your-domain.com}
       }
    ) {
        to
        message
        subject
        sent
  }
}
Clone this wiki locally