MessagingEmailProviderSendgrid

Send email through SendGrid: one class of static functions that deliver either a plain text message with an optional HTML body and attachments, or a SendGrid dynamic template filled with your own data.

This page is a pure reference. For how the framework fits together, see the Guide.

Classes

MessagingEmailProviderSendGrid

The SendGrid email provider: static functions that send an email through the SendGrid API using the configured API key. Each function validates its arguments, sends the message, and throws when SendGrid does not accept it.

Send

MessagingEmailProviderSendGrid::Send(string $fromEmail, string $fromName, string $toEmail, string $toName, string $subject, string $bodyText, string|null $optionalBodyHtml = null, array $attachments = []): void

Send an email through SendGrid with a plain text body, an optional HTML body, and optional attachments. Throws when SendGrid does not return a 202 accepted response.

NameTypeDescription
$fromEmailstringThe sender email address.
$fromNamestringThe sender display name.
$toEmailstringThe recipient email address.
$toNamestringThe recipient display name.
$subjectstringThe email subject line.
$bodyTextstringThe plain text body of the email.
$optionalBodyHtmlstring|nullAn HTML body to add, or null for none.
$attachmentsarrayA map of attachment name to raw content; each is base64 encoded and attached.

Returns void

SendGridTemplate

MessagingEmailProviderSendGrid::SendGridTemplate(string $fromEmail, string $fromName, string $toEmail, string $toName, string $templateId, array $dynamicData): void

Send an email through SendGrid using a dynamic template, supplying the values that fill it. Throws when SendGrid does not return a 202 accepted response.

NameTypeDescription
$fromEmailstringThe sender email address.
$fromNamestringThe sender display name.
$toEmailstringThe recipient email address.
$toNamestringThe recipient display name.
$templateIdstringThe SendGrid dynamic template id to use.
$dynamicDataarrayA map of template variable name to value, added as dynamic template data.

Returns void