Exemple #1
0
function _cdashsendgrid($to, $subject, $body)
{
    global $CDASH_EMAIL_FROM, $CDASH_EMAIL_REPLY, $CDASH_SENDGRID_API_KEY;
    $sg = new \SendGrid($CDASH_SENDGRID_API_KEY);
    $mail = new SendGrid\Mail();
    $mail->setFrom(new SendGrid\Email(null, $CDASH_EMAIL_FROM));
    $mail->setSubject($subject);
    $mail->setReplyTo(new SendGrid\Email(null, $CDASH_EMAIL_REPLY));
    $mail->addContent(new SendGrid\Content('text/plain', $body));
    foreach (explode(', ', $to) as $recipient) {
        $personalization = new SendGrid\Personalization();
        $personalization->addTo(new SendGrid\Email(null, $recipient));
        $mail->addPersonalization($personalization);
    }
    $response = $sg->client->mail()->send()->post($mail);
    if ($response->statusCode() === 202) {
        return true;
    } else {
        add_log('Failed to send email via sendgrid status code: ' . $response->statusCode(), '_cdashsendgrid', LOG_ERR);
        return false;
    }
}