public function sendEmail($mail) { $setting = Setting::find()->where(['id' => 1])->one(); $username = $setting->sendgridUsername; $password = $setting->sendgridPassword; $mail_admin = $setting->emailAdmin; $sendgrid = new \SendGrid($username, $password, array("turn_off_ssl_verification" => true)); $email = new \SendGrid\Email(); $subject = 'Registrasi Berhasil'; $body = 'Thanks ' . $this->username . ','; $body .= "\n"; $body .= "Registrasi anda berhasil, kami akan segera mereview kembali registrasi anda. \n"; $body .= "Thanks, \n"; $body .= Yii::$app->name; $body_message = $this->template($subject, $body, $logo); $email->addTo($mail)->setFrom($mail_admin)->setSubject('Registrasi berhasil')->setHtml($body_message)->addCategory("registrasi"); $response = $sendgrid->send($email); //return $response; //send whatsapp if ($setting->whatsappNumber && $setting->whatsappPassword) { $number = $setting->whatsappNumber; $app = Yii::$app->name; $password = $setting->whatsappPassword; $w = new WhatsApp($number, $app, $password); $w->send($setting->whatsappSend, $body); } }
protected function sendEmail($to, $from, $body, $subject) { $sendgrid = new SendGrid('fake username2', 'fake password 2'); $email = new SendGrid\Email($this->username, $this->password); $email->addTo($to)->setFrom($from)->setSubject($subject)->setText($body)->setHtml($body); return $sendgrid->send($email); }
public function send(MessageInterface $message) { if (count($message->getToList()) === 0) { // TODO FIXED EXCEPTION throw new \Exception(); } foreach ($message->getToList() as $email) { if (!$this->validateEmail($email)) { // TODO FIXED EXCEPTION throw new \Exception(); } } $sendgrid = new \SendGrid(env("SENDGRID_USERNAME"), env("SENDGRID_PASSWORD")); $email = new \SendGrid\Email(); $email->addTo($message->getToList())->setFrom($message->getFrom())->setSubject($message->getSubject())->setText($message->getTextBody())->setHtml($message->getHtmlBody()); if (is_array($message->getBccList())) { $email->addBcc($message->getBccList()); } $email->setAttachments($message->getAttachments()); try { $sendgrid->send($email); } catch (\Exception $e) { throw $e; } }
public function actionSendChat() { if (!empty($_POST)) { echo \sintret\chat\ChatRoom::sendChat($_POST); $message = Yii::$app->user->identity->username . ' : ' . $_POST['message']; $pos = strpos($message, "@"); $setting = \app\models\Setting::findOne(1); if ($pos !== FALSE) { // $w = new WhatsApp($number, $app, $password); $usernameSendgrid = $setting->sendgridUsername; $passwordSendgrid = $setting->sendgridPassword; $users = \app\models\User::find()->where(['status' => \app\models\User::STATUS_ACTIVE])->all(); foreach ($users as $model) { $aprot = '@' . strtolower($model->username); if (strpos($message, $aprot) !== false) { $sendgrid = new \SendGrid($usernameSendgrid, $passwordSendgrid, array("turn_off_ssl_verification" => true)); $email = new \SendGrid\Email(); $email->addTo($model->email)->setFrom($setting->emailSupport)->setSubject('Chat from ' . $setting->applicationName)->setHtml($message); $sendgrid->send($email); } else { } } } } }
function sendEmail($to, $subject, $message) { $sendgrid = new SendGrid('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'); $email = new SendGrid\Email(); $email->addTo($to)->setFrom('*****@*****.**')->setSubject($subject)->setText('text')->setHtml($message); $sendgrid->send($email); }
public function sendMail() { /* @var $user User */ $user = User::findOne(['status' => User::STATUS_ACTIVE, 'email' => $this->email]); if ($user) { if (!User::isPasswordResetTokenValid($user->password_reset_token)) { $user->generatePasswordResetToken(); } if ($user->save()) { $setting = Setting::find()->where(['id' => 1])->one(); $username = $setting->sendgridUsername; $password = $setting->sendgridPassword; $mail_admin = $setting->emailAdmin; $sendgrid = new \SendGrid($username, $password, array("turn_off_ssl_verification" => true)); $email = new \SendGrid\Email(); $mail = $user->email; //echo $user->email;exit(0); $resetLink = \Yii::$app->urlManager->createAbsoluteUrl(['site/reset-password', 'token' => $user->password_reset_token]); $body_message = 'Hello ' . Html::encode($user->username) . ', <br> Follow the link below to reset your password: <br> ' . Html::a(Html::encode($resetLink), $resetLink); $email->addTo($user->email)->setFrom($mail_admin)->setSubject('Password reset for ' . \Yii::$app->name)->setHtml($body_message); $response = $sendgrid->send($email); //print_r($response); exit(0); return $response; } } return false; }
private function map_to_swift(SendGrid\Email $mail) { $message = new \Swift_Message($mail->getSubject()); /* * Since we're sending transactional email, we want the message to go to one person at a time, rather * than a bulk send on one message. In order to do this, we'll have to send the list of recipients through the headers * but Swift still requires a 'to' address. So we'll falsify it with the from address, as it will be * ignored anyway. */ $message->setTo($mail->to); $message->setFrom($mail->getFrom(true)); $message->setCc($mail->getCcs()); $message->setBcc($mail->getBccs()); if ($mail->getHtml()) { $message->setBody($mail->getHtml(), 'text/html'); if ($mail->getText()) { $message->addPart($mail->getText(), 'text/plain'); } } else { $message->setBody($mail->getText(), 'text/plain'); } if ($replyto = $mail->getReplyTo()) { $message->setReplyTo($replyto); } $attachments = $mail->getAttachments(); //add any attachments that were added if ($attachments) { foreach ($attachments as $attachment) { $message->attach(\Swift_Attachment::fromPath($attachment['file'])); } } $message_headers = $message->getHeaders(); $message_headers->addTextHeader("x-smtpapi", $mail->smtpapi->jsonString()); return $message; }
public function send(SendGrid\Email $email) { $fields = $email->toWebFormat(); $headers = array(); if ("credentials" == $this->method) { $fields['api_user'] = $this->username; $fields['api_key'] = $this->password; } else { $headers = array('Authorization' => 'Bearer ' . $this->apikey); } $files = preg_grep('/files/', array_keys($fields)); foreach ($files as $k => $file) { $fields[$file] = file_get_contents(substr($fields[$file], 1)); } $data = array('body' => $fields); if (count($headers)) { $data['headers'] = $headers; } $response = wp_remote_post(self::URL, $data); if (!is_array($response) or !isset($response['body'])) { return false; } if ("success" == json_decode($response['body'])->message) { return true; } return false; }
function sendEmail($to, $subject, $message) { $sendgrid = new SendGrid('ilmarching_mail', 'aksld8jc98aisndcasd98ch98273hnd9das8ejncm'); $email = new SendGrid\Email(); $email->addTo($to)->setFrom('*****@*****.**')->setSubject($subject)->setText('text')->setHtml($message); $sendgrid->send($email); }
function send_email($to_address, $subject, $text, $hmtl) { global $SENDGRID_USER, $SENDGRID_PASS; $sendgrid = new SendGrid($SENDGRID_USER, $SENDGRID_PASS); $email = new SendGrid\Email(); $email->addTo($to_address)->setFrom('*****@*****.**')->setSubject($subject)->setText($text)->setHtml($html); $sendgrid->send($email); }
public function send(SendGrid\Email $email) { $form = $email->toWebFormat(); $form['api_user'] = $this->api_user; $form['api_key'] = $this->api_key; $response = $this->makeRequest($form); return $response; }
public function testSendResponseWithSslOptionFalse() { $sendgrid = new SendGrid("foo", "bar", array("switch_off_ssl_verification" => true)); $email = new SendGrid\Email(); $email->setFrom('*****@*****.**')->setSubject('foobar subject')->setText('foobar text')->addTo('*****@*****.**')->addAttachment('./text'); $response = $sendgrid->send($email); $this->assertEquals("Bad username / password", $response->errors[0]); }
/** * Simple function to send and e-mail * @param string $dest Mail destination * @param string $title Mail title * @param string $body Mail body */ public static function sendMail($dest, $title, $body) { require_once 'vendor/autoload.php'; include 'values/mailCredentials.php'; $sendgrid = new SendGrid($mail_user, $mail_password); $email = new SendGrid\Email(); $email->addTo($dest)->setFrom('*****@*****.**')->setSubject($title)->setText($body); $response = $sendgrid->send($email); return $response->getCode() == 200; }
/** * Makes a post request to SendGrid to send an email * @param SendGrid\Email $email Email object built * @throws SendGrid\Exception if the response code is not 200 * @return stdClass SendGrid response object */ public function send(SendGrid\Email $email) { $form = $email->toWebFormat(); $form['api_user'] = $this->apiUser; $form['api_key'] = $this->apiKey; $response = $this->postRequest($this->endpoint, $form); if ($response->code != 200) { throw new SendGrid\Exception($response->raw_body, $response->code); } return $response; }
public function testConstruction() { $sendgrid = new SendGrid("foo", "bar"); $smtp = $sendgrid->smtp; $this->assertEquals(new SendGrid\Smtp("foo", "bar"), $smtp); $message = new SendGrid\Email(); $message->setFrom('*****@*****.**')->setFromName('John Doe')->setSubject('foobar subject')->setText('foobar text')->addTo('*****@*****.**')->addAttachment("mynewattachment.jpg"); $this->assertEquals(get_class($smtp), 'SendGrid\\Smtp'); $this->setExpectedException('SendGrid\\AuthException'); $smtp->send($message); }
/** * Sends an email using the Sendgrid Email API. * * @return void */ protected function _sendWithSendgrid() { try { $sendgrid = new \SendGrid(Settings::config()->transport_token); $email = new \SendGrid\Email(); $email->addTo($this->email)->setFrom(Settings::config()->transport_email)->setSubject($this->subject)->setHtml($this->message); $sendgrid->send($email); } catch (\SendGrid\Exception $e) { Debugger::log($e); } }
public function send(SendGrid\Email $email) { $form = $email->toWebFormat(); $form['api_user'] = $this->username; $form['api_key'] = $this->password; // option to ignore verification of ssl certificate if (isset($this->options['turn_off_ssl_verification']) && $this->options['turn_off_ssl_verification'] == true) { \Unirest::verifyPeer(false); } $response = \Unirest::post($this->url, array(), $form); return $response->body; }
public function send(SendGrid\Email $email) { $form = $email->toWebFormat(); $form['api_user'] = $this->api_user; $form['api_key'] = $this->api_key; // option to ignore verification of ssl certificate if (isset($this->options['turn_off_ssl_verification']) && $this->options['turn_off_ssl_verification'] == true) { \Unirest::verifyPeer(false); } $response = \Unirest::post($this->url, array('User-Agent' => 'sendgrid/' . $this->version . ';php'), $form); return $response->body; }
/** * Test sending a request with bad credentials and SSL verification off. */ public function testSendResponseWithSslOptionFalse() { $sendgrid = new \SendGrid\Client('token123456789', ['switch_off_ssl_verification' => TRUE]); $email = new \SendGrid\Email(); $email->setFrom('*****@*****.**')->setSubject('foobar subject')->setText('foobar text')->addTo('*****@*****.**')->addAttachment('./tests/text'); try { $response = $sendgrid->send($email); } catch (\GuzzleHttp\Exception\ClientException $e) { $response = $e->getResponse(); $responseBodyAsString = $response->getBody()->getContents(); } $this->assertContains('The provided authorization grant is invalid, expired, or revoked', $responseBodyAsString); }
static function sendEmail($to, $from, $subject, $message, $cc) { //User credentials $sendgrid_username = "******"; $sendgrid_password = "******"; //Set SendGrid Parameters $sendgrid = new SendGrid($sendgrid_username, $sendgrid_password, array("turn_off_ssl_verification" => true)); //instantiate library class $email = new SendGrid\Email(); //Set variables(to,cc,from,subject, message & headers for email) and send email $email->addTo($to)->addTo($cc)->setFrom($from)->setSubject($subject)->setCc($cc)->setHtml($message)->addHeader('X-Sent-Using', 'SendGrid-API')->addHeader('X-Transport', 'web'); //Wait for email response $response = $sendgrid->send($email); }
/** * Makes a post request to SendGrid to send an email * * @param SendGrid\Email $email Email object built * * @throws SendGrid\Exception if the response code is not 200 * @return stdClass SendGrid response object */ public function send(SendGrid\Email $email) { $form = $email->toWebFormat(); // Using username password if ($this->apiUser !== null) { $form['api_user'] = $this->apiUser; $form['api_key'] = $this->apiKey; } $response = $this->postRequest($this->endpoint, $form); if ($response->code != 200 && $this->options['raise_exceptions']) { throw new SendGrid\Exception($response->raw_body, $response->code); } return $response; }
public function deliver($message) { $sendgrid = new \SendGrid($this->username, $this->password, $this->options); $email = new \SendGrid\Email(); $to = $message->getTo(); if (is_array($to)) { foreach ($to as $rcpt) { $email->addTo($rcpt); } } else { $email->addTo($to); } $email->setFrom($this->from)->setFromName($this->from_name)->setSubject($message->getSubject())->setText($message->renderText())->setHtml($message->renderHtml()); $sendgrid->send($email); }
public function send() { $options = array('turn_off_ssl_verification' => true); $sendgrid = new \SendGrid($this->username, $this->password, $options); $email = new \SendGrid\Email(); $email->addTo($this->to)->setFrom($this->from)->setSubject($this->subject)->setFromName($this->fromName)->setHtml($this->conteudo)->setCc($this->from)->addFilter('templates', 'enabled', 1)->addFilter('templates', 'template_id', $this->template); try { $sendgrid->send($email); return array('enviado' => true, 'mensagem' => 'Enviado com sucesso'); } catch (\SendGrid\Exception $e) { $string = ''; foreach ($e->getErrors() as $er) { $string .= $e->getCode() . ' - ' . $er . '<br/>'; } return array('enviado' => false, 'mensagem' => $string); } }
/** * Send Email * * Sends email to designated recipient with subject line and message. * * @param string $sub * @param string $msg * @return true * @throws Exception */ public function send($sub, $msg) { if (!is_string($sub) && !is_string($msg)) { throw new Exception("Email message or subject is not string: " . $sub . ' ' . $msg); } $email = new \SendGrid\Email(); $email->setFrom($this->config->get('fromEmail'))->setFromName('Research Botnet')->addTo($this->recipient)->setSubject('Research Botnet: ' . $sub)->setText($msg); try { $this->sendgrid->send($email); } catch (\SendGrid\Exception $e) { $errors = ''; foreach ($e->getErrors() as $er) { $errors .= $er . ', '; } throw new Exception("SendGrid send exception: " . $e->getCode() . ' ' . $errors); } return true; }
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)); }
private function processEmailHeaders($headers, SendGrid\Email $email) { if ($headers && is_array($headers)) { if (isset($headers[self::Header_CC])) { foreach (explode(',', $headers[self::Header_CC]) as $cc) { $email->addCc(trim($cc)); } } if (isset($headers[self::Header_BCC])) { foreach (explode(',', $headers[self::Header_BCC]) as $bcc) { $email->addBcc(trim($bcc)); } } if (isset($headers[self::Header_ReplyTo])) { $email->setReplyTo($headers[self::Header_ReplyTo]); } } return $email; }
protected function sendEmail($to, $subj, $text, $html = null) { $email = new \SendGrid\Email(); $email->addCategory($subj); $email->addTo($to); $email->setFrom('*****@*****.**'); $email->setFromName('Edge conf'); $email->setSubject($subj); $email->setText($text); if ($html) { $emogrifier = new \Pelago\Emogrifier($html, file_get_contents(realpath(__DIR__ . '/../../../public/css/email.css'))); $email->setHtml($emogrifier->emogrify()); } $sendgrid = new \SendGrid($this->app->config->sendgrid->username, $this->app->config->sendgrid->password); $resp = $sendgrid->send($email); }
function sendgridEmail($name, $email_address, $phone, $message) { $name = htmlspecialchars($name); $email_address = htmlspecialchars($email_address); $phone = htmlspecialchars($phone); $message = htmlspecialchars($message); $html = "<p>Salut <strong>BoostU</strong>!</p>\r\n <p>Vous venez de recevoir un demande d'information:</p> <br>\r\n <p><strong>Nom:</strong> " . $name . "</p>\r\n <p><strong>Email:</strong> " . $email_address . "</p>\r\n <p><strong>Numéro de téléphone:</strong> " . $phone . "</p>\r\n <p><strong>Message:</strong><br>" . $message . "</p><br><br>\r\n <p style='color: grey;'>Bonne journée !</p>"; $sendgrid = new SendGrid('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'); $email = new SendGrid\Email(); $email->addSmtpapiTo('*****@*****.**')->setFrom('*****@*****.**')->setSubject('Contact information from landing page')->setText('Salut BoostU')->setHtml($html); // Or catch the error try { $sendgrid->send($email); } catch (\SendGrid\Exception $e) { echo $e->getCode(); foreach ($e->getErrors() as $er) { echo $er; } } }
/** * Controller made to launch temporary tests */ public function tests() { echo 'tests'; $f3 = \Base::instance(); $sendgrid = new \SendGrid('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'); $emails = explode("\n", file_get_contents('app/controllers/emails.txt')); //$emails = array('*****@*****.**', '*****@*****.**'); foreach ($emails as $email) { $mail = new \SendGrid\Email(); $mail->addTo($email)->setFrom('*****@*****.**')->setSubject('Lunch')->setHtml(\Template::instance()->render('mail.html')); try { $sendgrid->send($mail); echo "Mail to (sha1 of the email) " . sha1($email) . " sent !<br />\n"; } catch (\SendGrid\Exception $e) { echo $e->getCode(); foreach ($e->getErrors() as $er) { echo $er; } } } /*$email = new \SendGrid\Email(); $email ->addTo('*****@*****.**') ->setFrom('*****@*****.**') ->setSubject('Subject goes here') ->setText('Hello World!') ->setHtml('<strong>Hello World!</strong>') ; try { $sendgrid->send($email); echo 'Mail sent !'; } catch(\SendGrid\Exception $e) { echo $e->getCode(); foreach($e->getErrors() as $er) { echo $er; } }*/ }
protected function sendEmail($subject) { // If there is a message to send, send it if (!empty($this->message)) { self::printLog(' - Sending email'); // Send email $sendgrid = new \SendGrid(SENDGRID_KEY); $email = new \SendGrid\Email(); $email->addTo(TO_ADDRESS)->setFrom(FROM_ADDRESS)->setSubject($subject)->setHtml($this->message); try { $sendgrid->send($email); self::printLog(' - Email sent'); } catch (\SendGrid\Exception $e) { self::printLog($e->getCode()); foreach ($e->getErrors() as $er) { self::printLog($er); } } } else { self::printLog(' - No email to send'); } }