Skip to content

Instantly share code, notes, and snippets.

View sebmih's full-sized avatar

Sebastian Mihalache sebmih

  • DeepStream
  • Iași
View GitHub Profile
@sebmih
sebmih / NLAPI1.php
Last active December 19, 2015 21:19
A simple PHP script that allows you to add multiple recipients in a NL list using the API.
<?php
$email = array('andreis@sendgrid.com','andrei2@sendgrid.com');
$name = array('andrei1','andrei2');
for($i=0;$i<count($email);$i++)
{
$data[] = json_encode(array('email' => $email[$i], 'name' => $name[$i]));
}
$url = 'http://sendgrid.com/';
@sebmih
sebmih / PHPmail.php
Created July 17, 2013 10:16
PHP's mail() function with SendGrid' SMTPAPI
<?php
$headers = array();
$headers[] = "MIME-Version: 1.0";
$headers[] = "Content-type: text/plain; charset=iso-8859-1";
$headers[] = "From: Sender Name <sender@domain.com>";
$headers[] = "Bcc: JJ Chong <bcc@domain2.com>";
$headers[] = "Reply-To: Recipient Name <receiver@domain3.com>";
$headers[] = "Subject: {$subject}";
$headers[] = "X-Mailer: PHP/".phpversion();
$headers[] = "X-SMTPAPI: {"category":"testing123"}";
@sebmih
sebmih / WebAPIunique
Created July 17, 2013 10:24
The $params array using Unique Arguments
$params = array(
'api_user' => $user,
'api_key' => $pass,
'to' => $adresa,
'subject' => $subiect,
'text' => $mesaj,
'html' => $html,
'x-smtpapi' => '{"unique_args": {"campaign_id":"121"}}',
'from' => $from
);
@sebmih
sebmih / WebAPIatt.php
Created July 17, 2013 10:25
A complete script that sends emails with attachments (built within the script itself) using the Web API
<?php
// this is where file.txt is created and content is added.
$my_file = 'file.txt';
$handle = fopen($my_file, 'w') or die('Cannot open file: '.$my_file);
$data = 'This is the actual content of the text file.';
fwrite($handle, $data);
$url = 'http://sendgrid.com/';
$user = '******';
$pass = '******';
@sebmih
sebmih / WebAPIstats.php
Created July 17, 2013 10:27
A complete script that grabs SendGrid Stats and displays them
<?php
$url = 'http://sendgrid.com/';
$user = 'SG_username';
$pass = 'SG_password';
$days = 'x';
$params = array(
'days' => $days,
'api_user' => $user,
'api_key' => $pass
@sebmih
sebmih / SMTPAPI.json
Created July 18, 2013 04:59
Here's the JSON needed to activate the Subscription Tracking app
{
"filters":
{
"subscriptiontrack":
{
"settings":
{
"enable":1,
"text/html":"If you would like to unsubscribe and stop receiving these emails <% click here %>",
"text/plain":"If you would like to unsubscribe and stop receiving these emails click here: <% %>."
@sebmih
sebmih / nladd.php
Created July 19, 2013 07:56
A script that adds a new newsletter into a user's dashboard.
<?php
$url = 'http://sendgrid.com/';
$user = '*****';
$pass = '*****';
$identity = 'address1';
$params = array(
'api_user' => $user,
'api_key' => $pass,
@sebmih
sebmih / nlapisch.php
Last active December 20, 2015 04:19
A working script to schedule a newsletter.
<?php
$url = 'http://sendgrid.com/';
$user = "sebfree";
$pass = "******";
$nl_name = "NLAPI_test3";
$send_time = "2013-07-25T09:00:00+02:00";
$params = array(
'api_user' => $user,
'api_key' => $pass,
@sebmih
sebmih / webapiattup.php
Created July 31, 2013 10:00
A working PHP script that uses a local file as an attachment via the Web API.
<?php
$url = 'http://sendgrid.com/';
$user = '******';
$pass = '******';
$fileName = 'music.mp3';
$filePath = dirname(__FILE__);
$params = array(
'api_user' => $user,
@sebmih
sebmih / uuencode.txt
Created August 1, 2013 06:31
The source of an email containing an Uuencoded attachment.
From: indexhelp@db.com
Message-Id: <201307292145.r6TLjuwO016779@nyiqcalp1.us.db.com>
X-Authentication-Warning: nyiqcalp1.us.db.com: dbiqcalp set sender to
indexhelp@db.com using -f
To: DBXIndexLevels@list.db.com, rohit.padebettu@db.com,
dbx-import-ce2dd12b@sendgrid.dbxus.com
Subject: DBCS Index level Report, Date : 20130726
X-BeenThere: dbxindexlevels@list.db.com
Precedence: list
List-Id: dbxindexlevels.list.db.com