Esempio n. 1
0
 public static function notify($options)
 {
     $body = self::_body($options);
     $emails = isset($options["emails"]) ? $options["emails"] : array($options["user"]->email);
     $delivery = isset($options["delivery"]) ? $options["delivery"] : "sendgrid";
     switch ($delivery) {
         default:
             $sendgrid = self::_sendgrid();
             $email = new \SendGrid\Email();
             $email->setSmtpapiTos($emails)->setFrom('*****@*****.**')->setFromName("HealthLitmus Team")->setSubject($options["subject"])->setHtml($body);
             if (isset($options["attachment"])) {
                 $email->setAttachment($options["attachment"]);
             }
             $sendgrid->send($email);
             break;
     }
     self::log(implode(",", $emails));
 }
Esempio n. 2
0
 public function testSetSmtpapiTos()
 {
     $email = new \SendGrid\Email();
     $email->setSmtpapiTos(['*****@*****.**']);
     $this->assertEquals(['*****@*****.**'], $email->getSmtpapi()->to);
 }
Esempio n. 3
0
 protected function notify($options)
 {
     $body = $this->getBody($options);
     $emails = isset($options["emails"]) ? $options["emails"] : array($options["user"]->email);
     switch ($options["delivery"]) {
         default:
             $sendgrid = $this->sendgrid();
             $email = new \SendGrid\Email();
             $email->setSmtpapiTos($emails)->setFrom('*****@*****.**')->setFromName("Likesbazar Team")->setSubject($options["subject"])->setHtml($body);
             $sendgrid->send($email);
             break;
     }
     $this->log(implode(",", $emails));
 }
<?php

require 'vendor/autoload.php';
$dotenv = new Dotenv\Dotenv(__DIR__);
$dotenv->load();
$api_key = $_ENV['API_KEY'];
$from = $_ENV['FROM'];
$tos = explode(',', $_ENV['TOS']);
$sendgrid = new SendGrid($api_key, array("turn_off_ssl_verification" => true));
$email = new SendGrid\Email();
$email->setSmtpapiTos($tos)->setFrom($from)->setFromName("送信者名")->setSubject("[sendgrid-php-example] mocloudユーザは%fullname%さん")->setText("%familyname% さんは何をしていますか?\r\n 彼は%place%にいます。")->setHtml("<strong> %familyname% さんは何をしていますか?</strong><br />彼は%place%にいます。")->addSubstitution("%fullname%", array("田中 太郎", "佐藤 次郎", "鈴木 三郎"))->addSubstitution("%familyname%", array("田中", "佐藤", "鈴木"))->addSubstitution("%place%", array("%office%", "%home%", "%office%"))->addSection('%office%', '中目黒')->addSection('%home%', '鹿児島')->addCategory('category1')->addHeader('X-Sent-Using', 'SendGrid-API')->addAttachment('./kanna.gif', 'owl.gif');
$response = $sendgrid->send($email);
var_dump($response);