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);
 }
Beispiel #2
0
 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;
     }
 }
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);
}
Beispiel #4
0
 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);
     }
 }
 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 {
                 }
             }
         }
     }
 }
Beispiel #6
0
 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 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;
 }
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);
}
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);
}
Beispiel #10
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;
 }
Beispiel #11
0
 /**
  * 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);
     }
 }
 function sendPlain($to, $from, $subject, $plainContent, $attachedFiles = false, $customheaders = false)
 {
     $mail = new SendGrid\Email();
     $sendgrid = $this->instanciate();
     $to = explode(',', $to);
     foreach ($to as $s1) {
         $mail->addTo(trim($s1));
     }
     $mail->setFrom(trim($from));
     $mail->setSubject($subject);
     $mail->setText($plainContent);
     $sendgrid->send($mail);
 }
Beispiel #13
0
 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);
 }
Beispiel #14
0
 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);
 }
Beispiel #15
0
 public function send(array $options)
 {
     $connection = $this->getConnection();
     $email = new \SendGrid\Email();
     $options = array_replace_recursive($this->defaults, $options);
     foreach ((array) $options['to'] as $to) {
         $email->addTo($to);
     }
     foreach ((array) $options['cc'] as $cc) {
         $email->addCc($cc);
     }
     foreach ((array) $options['bcc'] as $bcc) {
         $email->addBcc($bcc);
     }
     $email->setSubject($options['subject']);
     $email->setFrom($this->getFrom($options));
     if (!empty($options['category'])) {
         $email->setCategory($options['category']);
     }
     if (!empty($options['categories'])) {
         $email->setCategories($options['categories']);
     }
     if (!empty($options['text'])) {
         $email->setText($options['text']);
     }
     if (!empty($options['html'])) {
         $email->setHtml($options['html']);
     } elseif (!empty($options['layout']) && !empty($options['data'])) {
         $path = $this->_app->basePath . '/mail/sendgrid/' . $options['layout'] . '.html';
         if (!file_exists($path)) {
             $message = 'Layout "' . $options['layout'] . '" cannot be found in "/mail/sendgrid/".';
             if ($this->_version == 2) {
                 throw new \yii\web\NotFoundHttpException($message);
             } else {
                 throw new \CHttpException(404, $message);
             }
         }
         $params = array('subject' => $options['subject']);
         foreach ($options['data'] as $key => $value) {
             $params['{{' . $key . '}}'] = $value;
         }
         $html = file_get_contents($path);
         $html = strtr($html, $params);
         $email->setHtml($html);
     }
     return $response = $connection->send($email);
 }
Beispiel #16
0
 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);
     }
 }
Beispiel #17
0
 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');
     }
 }
Beispiel #18
0
 /**
  * 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;
                 }
             }*/
 }
Beispiel #19
0
 /**
  * Returns compiled email to be sent to the user with deny message
  *
  * @param string $email   The user's email address
  * @param string $ver     The random verification code for the user
  * @param string $sendgm  SendGrid instance
  * @return $sendgm        Return compiled mail
  */
 public function sendDenyEmail($email)
 {
     $sendgrid = new SendGrid($_ENV['SG_KEY']);
     $mail = new SendGrid\Email();
     $mail->addTo($email)->setFrom('*****@*****.**')->setFromName('WolvesOfOld')->setSubject('[WolvesOfOld] Account Denied')->setText("We're sorry. . .\n \nYour request has been denied. \n\nPlease contact us via the 'Contact Us' tab or ask one of our Clan admins.\n \nThank you for your interest in the WolvesOfOld!\n \n--\nThanks!\n \nRairaku\nwoobs.herokuapp.com")->setSubstitutions(array('%email%' => array($email)));
     try {
         $sendgrid->send($mail);
     } catch (\SendGrid\Exception $e) {
         echo $e->getCode();
         foreach ($e->getErrors() as $er) {
             echo $er;
         }
         return "<h2> Error </h2>" . "<p> There was an error sending" . " deny email. </p>";
     }
     $sql = "DELETE FROM users\n                WHERE Email=:email";
     if ($stmt = $this->_db->prepare($sql)) {
         $stmt->bindParam(":email", $email, PDO::PARAM_STR);
         $stmt->execute();
         $stmt->closeCursor();
         $userID = $this->_db->lastInsertId();
         $url = dechex($userID);
         return "<h2> Email has been removed. </h2>";
     } else {
         return "<h2> Error </h2><p> Couldn't delete the " . "user information from the database. </p>";
     }
 }
Beispiel #20
0
<?php

require 'libs/sendgrid/vendor/autoload.php';
require 'libs/sendgrid/sendgrid-php.php';
$sendgrid = new SendGrid("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");
$email = new SendGrid\Email();
$nome = isset($_POST["nome"]) ? $_POST["nome"] : FALSE;
$mail = isset($_POST["email"]) ? $_POST["email"] : FALSE;
$telefone = isset($_POST["telefone"]) ? $_POST["telefone"] : FALSE;
if ($nome && $mail && $telefone) {
    $mail = (string) $mail;
    $email->addTo($mail)->setFrom("*****@*****.**")->setSubject("eBook - Gestão de Representantes Comerciais")->setHtml("<!DOCTYPE html>\n\t\t\t\t\t\t<html lang=\"pt-BR\">\n\t\t\t\t\t\t<head>\n\t\t\t\t\t\t\t<meta charset=\"UTF-8\" />\n\t\t\t\t\t\t\t<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />\n\t\t\t\t\t\t\t<title>eBook - Gestão de Representantes Comerciais | Meus Pedidos</title>\n\t\t\t\t\t\t</head>\n\t\t\t\t\t\t<body>\n\t\t\t\t\t\t\t<table style=\"width:100%\" bgcolor=\"white\" colspan=\"0\" cellpadding=\"0\" border=\"0\">\n\t\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t\t<td align=\"center\">\n\t\t\t\t\t\t\t\t\t\t<table bgcolor=\"white\" style=\"width:600px;\" colspan=\"0\" cellpadding=\"0\">\n\t\t\t\t\t\t\t\t\t\t\t<tr><td height=\"30\">&nbsp;</td></tr>\n\t\t\t\t\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t\t\t\t\t<td align=\"center\"><a href=\"https://meuspedidos.com.br\" target=\"_blank\" style=\"border:0\"><img src=\"http://evertondenis-mpdevtest.rhcloud.com/images/logo_mp_email.png\" width=\"142\" height=\"29\" alt=\"Meus Pedidos\"></a></td>\n\t\t\t\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t\t\t\t\t<td height=\"120\" align=\"center\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t<font style=\"font-family:Arial;font-size:18px; font-weight:normal; color:#4f4f4f\">Obrigada por baixar nosso<br></font>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<font style=\"font-family:Arial;font-size:22px; font-weight:bold; color:#5695e2\">eBook Gestão de Representantes Comerciais</font>\n\t\t\t\t\t\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t\t\t\t\t<td align=\"center\"><a href=\"http://simplest-marketing.s3.amazonaws.com/ebooks/livro-gestao-representantes.pdf\" target=\"_blank\" style=\"border:0\"><img src=\"http://evertondenis-mpdevtest.rhcloud.com/images/ebook-email.jpg\" width=\"283\" height=\"400\" alt=\"eBook - Gestão de Representantes Comerciais\"></a></td>\n\t\t\t\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t\t\t\t\t<td height=\"120\" align=\"center\"><a href=\"http://simplest-marketing.s3.amazonaws.com/ebooks/livro-gestao-representantes.pdf\" target=\"_blank\" style=\"border:0\"><img src=\"http://evertondenis-mpdevtest.rhcloud.com/images/btn-acessar-ebook.png\" width=\"310\" height=\"51\" alt=\"Acessar eBook\"></a></td>\n\t\t\t\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t\t\t\t\t<td height=\"80\" bgcolor=\"#f3f3f3\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t<table style=\"width:100%\" bgcolor=\"#f3f3f3\" colspan=\"0\" cellpadding=\"10px\" border=\"0\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<td align=\"left\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<a href=\"https://pt-br.facebook.com/meuspedidos.com.br\" target=\"_blank\" style=\"border:0; text-decoration:none; margin-right:5px\"><img src=\"http://evertondenis-mpdevtest.rhcloud.com/images/facebook.png\" width=\"19\" height=\"19\" alt=\"Facebook Meus Pedidos\"></a>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<a href=\"https://www.linkedin.com/company/meuspedidos\" target=\"_blank\" style=\"border:0; text-decoration:none;\"><img src=\"http://evertondenis-mpdevtest.rhcloud.com/images/linkedin.png\" width=\"19\" height=\"19\" alt=\"LinkedIn Meus Pedidos\"></a>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<a href=\"https://meuspedidos.com.br\" target=\"_blank\" style=\"float:right; color:#7C7C7C; font-size:14px;font-family:Arial; text-decoration:none; border:0\">www.<span style=\"font-family:Arial;font-size:20px; font-weight:bold\">meuspedidos</span>.com.br</a>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t\t\t\t\t\t\t</table>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t\t\t\t</table>\n\t\t\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t</table>\n\t\t\t\t\t\t</body>\n\t\t\t\t\t\t</html>")->addAttachment(__DIR__ . "/ebooks/livro-gestao-representantes.pdf");
    try {
        $sendgrid->send($email);
        echo 'Você receberá o eBook em seu e-mail';
    } catch (\SendGrid\Exception $e) {
        echo $e->getCode();
        foreach ($e->getErrors() as $er) {
            echo $er;
        }
    }
}
    Response::json(400, $errors);
}
$form->fill_values();
$errors = $form->validate_format();
if (!empty($errors)) {
    Response::json(400, $errors);
}
// Get form values
$full_name = $form->value('full_name');
$email = $form->value('email');
$reason = $form->value('reason');
$subject = $form->value('subject');
$message = $form->value('message');
// Message template
$message_body = file_get_contents('../templates/_email_contact.html');
$message_body = str_replace(array('{{ full_name }}', '{{ email }}', '{{ reason }}', '{{ subject }}', '{{ message }}'), array($full_name, $email, $REASONS[$reason], $subject, $message), $message_body);
// Mail build
$mailer = new SendGrid(Config::$SENDGRID_USERNAME, Config::$SENDGRID_PASSWORD, Config::$SENDGRID_OPTIONS);
$message = new SendGrid\Email();
$message->addTo(Config::$CONTACT_FORM_TO);
$message->setReplyTo($email);
$message->setFrom($email);
$message->setFromName('Contacto Jedbangers');
$message->setSubject('Contacto | ' . $full_name);
$message->setHtml($message_body);
$response = $mailer->send($message);
if (strcmp($response->message, 'success') !== 0) {
    Response::json(500, 'El mensaje no pudo ser enviado. Error: ' . $response->errors[0]);
}
unset($_SESSION['token_form_contact']);
Response::json(200, 'Gracias! El mensaje fue enviado. Te responderemos a la brevedad.');
Beispiel #22
0
 public function testToWebFormatWithToName()
 {
     $email = new \SendGrid\Email();
     $email->addTo('*****@*****.**', 'Frank Foo');
     $email->setFrom('*****@*****.**');
     $json = $email->toWebFormat();
     $this->assertEquals($json['toname'], ['Frank Foo']);
 }
Beispiel #23
0
<?php

require 'vendor/autoload.php';
require 'lib/SendGrid.php';
require 'lib/Client.php';
Dotenv::load(__DIR__);
$sendgrid_apikey = getenv('SG_KEY');
$sendgrid = new SendGrid($sendgrid_apikey);
$email = new SendGrid\Email();
$templateId = '<template_id>';
$name = array('Elmer');
$email->addTo('*****@*****.**')->setFrom('*****@*****.**')->setSubject('Testing the PHP Library')->setText('I\'m text!')->setHtml('<strong>I\'m HTML!</strong>')->addFilter('templates', 'enabled', 1)->addFilter('templates', 'template_id', $templateId)->addSubstitution(":name", $name);
$sendgrid->send($email);
Beispiel #24
0
<?php

require 'vendor/autoload.php';
try {
    $dotenv = new Dotenv\Dotenv(__DIR__);
    $dotenv->load();
} catch (Exception $e) {
    error_log($e->getMessage());
}
$api_key = $_ENV['API_KEY'];
$from = $_ENV['FROM'];
$to = $_ENV['TO'];
$name = $_POST['name'];
$emailadd = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$sendgrid = new SendGrid($api_key);
$email = new SendGrid\Email();
$email->addTo($to)->setFrom($from)->setFromName("問合せフォーム")->setSubject("[ContactForm] {$subject}")->setText("Name: {$name} \r\nEmail: {$emailadd} \r\nSubject: {$subject} \r\nMessage: {$message} \r\n")->setHtml("<strong>Name:</strong> {$name}<br /> <strong>Email:</strong> {$emailadd}<br /> <strong>Subject:</strong> {$subject}<br /> <strong>Message:</strong> {$message}<br /> ")->addCategory('contact');
try {
    $response = $sendgrid->send($email);
    if ($response->code !== 200) {
        var_dump($response);
    }
    // 正常終了時にthanks.htmlへリダイレクト
    header('Location: thanks.html');
} catch (Exception $e) {
    var_dump($e);
}
exit;
    $emailto = $_POST['email'];
    $valid = FALSE;
    $query = " SELECT * FROM riot4.users WHERE username = ? and emailid = ?";
    $params = array($username, $emailto);
    $statement = sqlsrv_query($conn, $query, $params);
    if (sqlsrv_has_rows($statement)) {
        $_SESSION['random_key'] = rand(10000, 99999);
        $_SESSION['temp_user'] = $username;
        $user = '';
        /*removed from public visibility*/
        $pass = '';
        /*removed from public visibility*/
        $sendgrid = new SendGrid($user, $pass);
        $email = new SendGrid\Email();
        $msg = "<html>\n                        <body>\n                        <h1> Hi " . $username . ",</h1><h3>\n                        <br><br>Please use this key to change your password: "******"<br>Please ignore this mail if you haven't requested for a change of password.\n                        <br><br><br><br>\n                        <b>Warm Regards,</b><br>\n                        Team A<br>\n                        RIoT\n                        </h3>\n                        </body>\n                    </html>";
        $email->addTo($emailto)->setFrom("*****@*****.**")->addHeader('Sent-From-riot4.azurewebsites.net', 'SendGrid-API')->setSubject("RIoT one time key")->setHtml($msg);
        $response = $sendgrid->send($email);
        header("Location: pwd_reset.php");
    } else {
        $valid = TRUE;
    }
}
?>
<link rel="stylesheet" type="text/css" href="/Styles/Logon.css">
    <div id="main">
        <h2>Password Recovery</h2>
        <form action="pwd_recovery.php" method="post">
            <fieldset>
                <legend>Password Recovery</legend>
                <ol>
                    <li>
Beispiel #26
0
<?php

/**
 * Copyright (c) 2014 Keith Casey.
 *
 * This code is designed to accompany the lynda.com video course "Design Patterns in PHP"
 *   by Keith Casey. If you've received this code without seeing the videos, go watch the
 *   videos. It will make way more sense and be more useful in general.
 */
require 'vendor/autoload.php';
$twilio = new Services_Twilio('fake username', 'fake password');
$message = $twilio->account->messages->sendMessage('+14085551234', '+12125551234', 'Hello monkey!');
$sendgrid = new SendGrid('fake username2', 'fake password 2');
$email = new SendGrid\Email();
$email->addTo('*****@*****.**')->setFrom('*****@*****.**')->setSubject('My great subject line')->setText('Hello World!')->setHtml('<strong>Hello World!</strong>');
$sendgrid->send($email);
Beispiel #27
0
            <head>
                <meta charset="UTF-8">
                <title>OneCard Message</title>
                <link rel="stylesheet" href="' . $url . 'stylesheets/style.css">
            </head>

            <body>
                <div style="padding:10px; background:#09a360; font-size:24px; color:#fff;">
                    <a href="' . $url . '" style="border:none; float:left; padding-right: 20px; color:#fff; text-decoration:none;">
                        OneCard
                    </a>
                    Account Activation
                </div>
                <div style="padding:24px; padding-left:100px; font-size:17px;">Hello ' . $fn . ',<br /><br />Click the link below to activate your account when ready:<br /><br /><a href="' . $url . 'activation.php?id=' . $uid . '&e=' . $e . '&p=' . $p_hash . '">Click here to activate your account now</a><br /><br />Login after successful activation using your:<br />* E-mail Address: <b>' . $e . '</b>
                </div>
            </body>
        </html>';
                $message = new SendGrid\Email();
                $message->addTo($to)->setFrom($from)->setSubject($subject)->setHtml($text);
                $response = $sendgrid->send($message);
                if ($response) {
                    echo "signup_success";
                } else {
                    echo "signup_failure";
                }
                exit;
            }
        }
    }
    exit;
}
Beispiel #28
0
 /**
  * Sends an email using the Sendgrid Email API.
  *
  * @return void
  */
 protected function _sendWithSendgrid()
 {
     /*
      * Decrypt Key Information
      */
     list($iv, $hash) = explode('.', Settings::config()->sendgrid_api_key);
     list($username, $password) = explode('|', Components\Authentication::decrypt($hash, $iv));
     $sendgrid = new \SendGrid($username, $password);
     $email = new \SendGrid\Email();
     $email->addTo($this->email)->setFrom(Settings::config()->sendmail_email)->setSubject($this->subject)->setHtml($this->message);
     $sendgrid->send($email);
 }
Beispiel #29
0
 protected function send_email($email)
 {
     $send_email = FALSE;
     $sendgrid = new SendGrid(getenv("SENDGRID_USERNAME"), getenv("SENDGRID_PASSWORD"));
     $message = '<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"/></head><body>';
     $message .= '<div style="background-color:white;font-size:14px;font-family:\'Segoe UI\',Arial,Helvetica,sans-serif">';
     $message .= '<table style="background-color:#000000;width:100%;font-weight:bold;vertical-align:middle" cellspacing="1" cellpadding="3" border="0"><tbody><tr><td style="font-size:14px;font-family:\'Segoe UI\',Arial,Helvetica,sans-serif">';
     $message .= '<img border="0" src="' . base_url('assets/images/logo.png') . '" width="82" height="40"></td></tr></tbody></table>';
     foreach ($email['text'] as $line) {
         $message .= '<p style="background-color:white;font-size:14px;font-family:\'Segoe UI\',Arial,Helvetica,sans-serif">' . $line . '</p>';
     }
     $message .= '<hr noshade="" size="1">';
     $message .= '<div style="background-color:white;font-size:14px;font-family:\'Segoe UI\',Arial,Helvetica,sans-serif"><a style="text-decoration:none" href="https://www.facebook.com/chaarbhai" target="_blank">Chaar Bhai</a><span style="color: white;">0</span></div>';
     $message .= '<div style="color: #888888;background-color:white;font-size:14px;font-family:\'Segoe UI\',Arial,Helvetica,sans-serif"><strong>Note</strong>: This message has been sent from an unattended email box.</div>';
     $message .= '</div></body></html>';
     $mail = new SendGrid\Email();
     foreach ($email['recipients'] as $recipient) {
         if (!empty($recipient['email'])) {
             $mail->addTo($recipient['email'], $recipient['name']);
             $send_email = TRUE;
         }
     }
     if (isset($email['attachments'])) {
         foreach ($email['attachments'] as $attachment) {
             $mail->addAttachment($attachment['path'], $attachment['name']);
         }
     }
     $mail->setFrom('*****@*****.**')->setFromName('Chaar Bhai');
     $mail->setSubject($email['subject']);
     $mail->setHtml($message);
     if ($send_email) {
         //$sendgrid->send($mail);
     }
 }
function sendMail($data, $gCaptchaSecretKey, $SendGrid_API_KEY)
{
    $captcha = $data->g_recaptcha_response;
    $postdata = http_build_query(array('secret' => $gCaptchaSecretKey, 'response' => $captcha, 'remoteip' => $_SERVER['REMOTE_ADDR']));
    $opts = array('http' => array('method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded', 'content' => $postdata));
    $context = stream_context_create($opts);
    $response = file_get_contents("https://www.google.com/recaptcha/api/siteverify", false, $context);
    $response = json_decode($response, true);
    $mailResponse = array();
    if ($response["success"] === false) {
        header_status(200);
        $mailResponse['status'] = 'Error';
        $mailResponse['message'] = 'Robots Not allowed (Captcha verification failed)';
        echo json_encode($mailResponse);
    } else {
        try {
            $sendgrid = new SendGrid($SendGrid_API_KEY);
            $email = new SendGrid\Email();
            $email->addTo(array(' '), array('Clinton D\'souza'))->setFrom('*****@*****.**')->setFromName($data->name . ' (via. v12eventsdubai.com - Website)')->setReplyTo($data->address)->setSubject($data->subject)->setText(htmlentities($data->msg))->setHtml(htmlentities($data->msg));
            if (!$sendgrid->send($email)) {
                header_status(503);
                $response['status'] = 'Error';
                $response['message'] = 'Error sending message';
            } else {
                header_status(200);
                $response['status'] = 'Success';
                $response['message'] = 'Message Sent';
            }
            echo json_encode($response);
        } catch (exception $e) {
            header_status(503);
            $mailResponse['status'] = 'Error';
            $mailResponse['message'] = $e->getMessage();
            echo json_encode($response);
            die;
        }
    }
}