Subversion Repositories cheapmusic

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
103 - 1
<?php
2
// If you are using Composer
3
require 'vendor/autoload.php';
4
 
5
 
6
$apiKey = getenv('SENDGRID_API_KEY');
7
$sg = new \SendGrid($apiKey);
8
 
9
////////////////////////////////////////////////////
10
// Create a batch ID #
11
// POST /mail/batch #
12
 
13
$response = $sg->client->mail()->batch()->post();
14
echo $response->statusCode();
15
echo $response->body();
16
echo $response->headers();
17
 
18
////////////////////////////////////////////////////
19
// Validate batch ID #
20
// GET /mail/batch/{batch_id} #
21
 
22
$batch_id = "test_url_param";
23
$response = $sg->client->mail()->batch()->_($batch_id)->get();
24
echo $response->statusCode();
25
echo $response->body();
26
echo $response->headers();
27
 
28
////////////////////////////////////////////////////
29
// v3 Mail Send #
30
// POST /mail/send #
31
// This endpoint has a helper, check it out [here](https://github.com/sendgrid/sendgrid-php/blob/master/lib/helpers/mail/README.md).
32
 
33
$request_body = json_decode('{
34
  "asm": {
35
    "group_id": 1,
36
    "groups_to_display": [
37
      1,
38
      2,
39
      3
40
    ]
41
  },
42
  "attachments": [
43
    {
44
      "content": "[BASE64 encoded content block here]",
45
      "content_id": "ii_139db99fdb5c3704",
46
      "disposition": "inline",
47
      "filename": "file1.jpg",
48
      "name": "file1",
49
      "type": "jpg"
50
    }
51
  ],
52
  "batch_id": "[YOUR BATCH ID GOES HERE]",
53
  "categories": [
54
    "category1",
55
    "category2"
56
  ],
57
  "content": [
58
    {
59
      "type": "text/html",
60
      "value": "<html><p>Hello, world!</p><img src=[CID GOES HERE]></img></html>"
61
    }
62
  ],
63
  "custom_args": {
64
    "New Argument 1": "New Value 1",
65
    "activationAttempt": "1",
66
    "customerAccountNumber": "[CUSTOMER ACCOUNT NUMBER GOES HERE]"
67
  },
68
  "from": {
69
    "email": "sam.smith@example.com",
70
    "name": "Sam Smith"
71
  },
72
  "headers": {},
73
  "ip_pool_name": "[YOUR POOL NAME GOES HERE]",
74
  "mail_settings": {
75
    "bcc": {
76
      "email": "ben.doe@example.com",
77
      "enable": true
78
    },
79
    "bypass_list_management": {
80
      "enable": true
81
    },
82
    "footer": {
83
      "enable": true,
84
      "html": "<p>Thanks</br>The SendGrid Team</p>",
85
      "text": "Thanks,/n The SendGrid Team"
86
    },
87
    "sandbox_mode": {
88
      "enable": false
89
    },
90
    "spam_check": {
91
      "enable": true,
92
      "post_to_url": "http://example.com/compliance",
93
      "threshold": 3
94
    }
95
  },
96
  "personalizations": [
97
    {
98
      "bcc": [
99
        {
100
          "email": "sam.doe@example.com",
101
          "name": "Sam Doe"
102
        }
103
      ],
104
      "cc": [
105
        {
106
          "email": "jane.doe@example.com",
107
          "name": "Jane Doe"
108
        }
109
      ],
110
      "custom_args": {
111
        "New Argument 1": "New Value 1",
112
        "activationAttempt": "1",
113
        "customerAccountNumber": "[CUSTOMER ACCOUNT NUMBER GOES HERE]"
114
      },
115
      "headers": {
116
        "X-Accept-Language": "en",
117
        "X-Mailer": "MyApp"
118
      },
119
      "send_at": 1409348513,
120
      "subject": "Hello, World!",
121
      "substitutions": {
122
        "id": "substitutions",
123
        "type": "object"
124
      },
125
      "to": [
126
        {
127
          "email": "john.doe@example.com",
128
          "name": "John Doe"
129
        }
130
      ]
131
    }
132
  ],
133
  "reply_to": {
134
    "email": "sam.smith@example.com",
135
    "name": "Sam Smith"
136
  },
137
  "sections": {
138
    "section": {
139
      ":sectionName1": "section 1 text",
140
      ":sectionName2": "section 2 text"
141
    }
142
  },
143
  "send_at": 1409348513,
144
  "subject": "Hello, World!",
145
  "template_id": "[YOUR TEMPLATE ID GOES HERE]",
146
  "tracking_settings": {
147
    "click_tracking": {
148
      "enable": true,
149
      "enable_text": true
150
    },
151
    "ganalytics": {
152
      "enable": true,
153
      "utm_campaign": "[NAME OF YOUR REFERRER SOURCE]",
154
      "utm_content": "[USE THIS SPACE TO DIFFERENTIATE YOUR EMAIL FROM ADS]",
155
      "utm_medium": "[NAME OF YOUR MARKETING MEDIUM e.g. email]",
156
      "utm_name": "[NAME OF YOUR CAMPAIGN]",
157
      "utm_term": "[IDENTIFY PAID KEYWORDS HERE]"
158
    },
159
    "open_tracking": {
160
      "enable": true,
161
      "substitution_tag": "%opentrack"
162
    },
163
    "subscription_tracking": {
164
      "enable": true,
165
      "html": "If you would like to unsubscribe and stop receiving these emails <% clickhere %>.",
166
      "substitution_tag": "<%click here%>",
167
      "text": "If you would like to unsubscribe and stop receiveing these emails <% click here %>."
168
    }
169
  }
170
}');
171
$response = $sg->client->mail()->send()->post($request_body);
172
echo $response->statusCode();
173
echo $response->body();
174
echo $response->headers();