Created
April 1, 2019 11:48
-
-
Save cwicaksono/941e326e4935aa74f5ddab1469efa2e3 to your computer and use it in GitHub Desktop.
Snippet to send email using sparkpost API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$title = "Title goes here"' | |
$email_title = "Email subject goes here"; | |
$email_recipent = "email@domain.com"; | |
$message = "Put your html email body in <strong>here</strong>"; | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, 'https://api.sparkpost.com/api/v1/transmissions'); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"content\": {\"from\": \"info@okocepeduli.com\",\"subject\": \"$email_title\",\"html\": \"$message\"},\"recipients\": [{ \"address\": \"$email_recipent\" }]\n}"); | |
curl_setopt($ch, CURLOPT_POST, 1); | |
$headers = array(); | |
$headers[] = 'Authorization: REPLACE_THIS_WITH_YOUR_SPARKPOST_API_KEY'; | |
$headers[] = 'Content-Type: application/json'; | |
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); | |
$result = curl_exec($ch); | |
if (curl_errno($ch)) { | |
echo 'Error:' . curl_error($ch); | |
} | |
// get response from sparkpost | |
print_r($result); | |
curl_close ($ch); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment