-
-
Save andrebaptista/5615013 to your computer and use it in GitHub Desktop.
Revisions
-
andrebaptista revised this gist
May 20, 2013 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -4,6 +4,6 @@ $postmark = new Postmark("your-api-key","from-email","optional-reply-to-address"); if($postmark->to("[email protected]")->subject("Email Subject")->html_message("<p style='color: red'>Test mail</p>")->send()){ echo "Message sent"; } -
andrebaptista revised this gist
May 20, 2013 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -25,7 +25,7 @@ function send(){ $ch = curl_init('http://api.postmarkapp.com/email'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); curl_setopt($ch, CURLOPT_POSTFIELDS, html_entity_decode(json_encode($data))); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); $return = curl_exec($ch); $curl_error = curl_error($ch); @@ -50,7 +50,7 @@ function subject($subject){ } function html_message($body){ $this->data["HtmlBody"] = htmlentities("<html><body>".$body."</body></html>"); return $this; } -
mloberg revised this gist
Mar 10, 2011 . 1 changed file with 10 additions and 39 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,25 +1,18 @@ <?php /** * This is a simple library for sending emails with Postmark created by Matthew Loberg (http://mloberg.com) */ class Postmark{ private $api_key; private $data = array(); function __construct($apikey,$from,$reply=""){ $this->api_key = $apikey; $this->data["From"] = $from; $this->data["ReplyTo"] = $reply; } function send(){ @@ -28,7 +21,7 @@ function send(){ "Content-Type: application/json", "X-Postmark-Server-Token: {$this->api_key}" ); $data = $this->data; $ch = curl_init('http://api.postmarkapp.com/email'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); @@ -47,50 +40,28 @@ function send(){ } function to($to){ $this->data["To"] = $to; return $this; } function subject($subject){ $this->data["subject"] = $subject; return $this; } function html_message($body){ $this->data["HtmlBody"] = "<html><body>{$body}</body></html>"; return $this; } function plain_message($msg){ $this->data["TextBody"] = $msg; return $this; } function tag($tag){ $this->data["Tag"] = $tag; return $this; } } -
mloberg revised this gist
Mar 10, 2011 . 1 changed file with 1 addition and 3 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,9 +1,7 @@ <?php /** * This is a simple library for sending emails with Postmark created by Matthew Loberg (http://mloberg.com) */ class Postmark{ -
mloberg created this gist
Mar 10, 2011 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,9 @@ <?php require("postmark.php"); $postmark = new Postmark("your-api-key","from-email","optional-reply-to-address"); if($postmark->to("[email protected]")->subject("Email Subject")->plain_message("This is a plain text message.")->send()){ echo "Message sent"; } This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,98 @@ <?php /** * This is a simple library for sending emails with Postmark * * Usage: $this->postmark->to(email)->subject(subject)->message_type(message)->send(); */ class Postmark{ private $api_key; private $from; private $reply; private $message; private $message_type; private $to; private $subject; private $data; private $tag; function __construct($apikey,$from,$reply=""){ $this->api_key = $apikey; $this->from = $from; $this->reply = $reply; } function send(){ $headers = array( "Accept: application/json", "Content-Type: application/json", "X-Postmark-Server-Token: {$this->api_key}" ); $data = $this->prepare_data(); $ch = curl_init('http://api.postmarkapp.com/email'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); $return = curl_exec($ch); $curl_error = curl_error($ch); $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); // do some checking to make sure it sent if($http_code !== 200){ return false; }else{ return true; } } function to($to){ $this->to = $to; return $this; } function subject($subject){ $this->subject = $subject; return $this; } function html_message($body){ $this->message = "<html><body>{$body}</body></html>"; $this->message_type = 'html'; return $this; } function plain_message($msg){ $this->message = $msg; $this->message_type = 'text'; return $this; } function tag($tag){ $this->tag = $tag; return $this; } private function prepare_data(){ $data = array( 'Subject' => $this->subject ); $data['From'] = $this->from; $data['To'] = $this->to; if($this->reply){ $data['ReplyTo'] = $this->reply; } if($this->tag){ $data['Tag'] = $this->tag; } if($this->message_type == 'text'){ $data['TextBody'] = $this->message; }else{ $data['HtmlBody'] = $this->message; } return $data; } }