-
Notifications
You must be signed in to change notification settings - Fork 29
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: ["example@example.com"],
message: "Email body here",
subject: "Subject text here",
trap: "12345",
headers: ["From: site@example.com"] # Will default to WordPress@{your-domain.com}
}
) {
to
message
subject
sent
}
}