Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
; This file is for unifying the coding style for different editors and IDEs.
; More information at http://editorconfig.org

root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 4
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

; Works with some editors only
quote_type = single
max_line_length = 120
spaces_around_brackets = true
spaces_around_operators = true
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
v0.3.0 (2015-03-26)
===================

* Add IP Pool support
* Normalize project file using PHP-FIG convention

--

v0.2.0 (2014-01-23)
===================

Expand Down
45 changes: 27 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# smtpapi-php
# SMTPAPI-PHP

This php library allows you to quickly and more easily generate SendGrid X-SMTPAPI headers.

Expand All @@ -15,7 +15,7 @@ Add the following to your `composer.json` file.
{
"minimum-stability" : "dev",
"require": {
"sendgrid/smtpapi": "0.2.0"
"sendgrid/smtpapi": "0.3.0"
}
}
```
Expand All @@ -33,7 +33,7 @@ If you are not using Composer, simply download and install the **[latest package
Then require the library from package:

```php
require("path/to/smtpapi-php/smtpapi-php.php");
require('path/to/smtpapi-php/smtpapi-php.php');
```

Previous versions of the library can be found in the [version index](https://sendgrid-open-source.s3.amazonaws.com/index.html).
Expand Down Expand Up @@ -166,6 +166,13 @@ $header = new Smtpapi\Header();
$header->setASMGroupID(42);
```

## setIpPool

```php
$header = new Smtpapi\Header();
$header->setIpPool('pool_name');
```

### addFilter

```php
Expand All @@ -182,7 +189,7 @@ $filter = array(
'footer' => array(
'setting' => array(
'enable' => 1,
"text/plain" => 'You can haz footers!'
'text/plain' => 'You can haz footers!'
)
)
);
Expand All @@ -194,23 +201,25 @@ $header->setFilters($filter);
The following example builds the X-SMTPAPI headers and adds them to swiftmailer. [Swiftmailer](http://swiftmailer.org/) then sends the email through SendGrid. You can use this same code in your application or optionally you can use [sendgrid-php](http://github.com/sendgrid/sendgrid-php).

```php
$transport = Swift_SmtpTransport::newInstance('smtp.sendgrid.net', 587);
$transport->setUsername("sendgrid_username");
$transport->setPassword("sendgrid_password");
use Smtpapi\Header;

$mailer = Swift_Mailer::newInstance($transport);
$transport = \Swift_SmtpTransport::newInstance('smtp.sendgrid.net', 587);
$transport->setUsername('sendgrid_username');
$transport->setPassword('sendgrid_password');

$message = new Swift_Message();
$message->setTos(array("[email protected]"));
$message->setFrom("[email protected]");
$message->setSubject("Hello");
$message->setBody("%how% are you doing?");
$mailer = \Swift_Mailer::newInstance($transport);

$header = new Smtpapi\Header();
$header->addSubstitution("%how%", array("Owl"));
$message = new \Swift_Message();
$message->setTos(array('[email protected]'));
$message->setFrom('[email protected]');
$message->setSubject('Hello');
$message->setBody('%how% are you doing?');

$header = new Header();
$header->addSubstitution('%how%', array('Owl'));

$message_headers = $message->getHeaders();
$message_headers->addTextHeader("x-smtpapi", $header->jsonString());
$message_headers->addTextHeader(HEADER::NAME, $header->jsonString());

try {
$response = $mailer->send($message);
Expand All @@ -232,8 +241,8 @@ try {

The existing tests in the `test` directory can be run using [PHPUnit](https://github.com/sebastianbergmann/phpunit/) with the following command:

````bash
composer update --dev
```bash
composer install
cd test
../vendor/bin/phpunit
```
Expand Down
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "sendgrid/smtpapi",
"description": "Build SendGrid X-SMTPAPI headers in PHP.",
"version": "0.2.0",
"version": "0.3.0",
"homepage": "http://github.com/sendgrid/smtpapi-php",
"license": "MIT",
"keywords": ["SendGrid", "sendgrid", "email", "send", "grid", "smtpapi", "smtp", "api", "xsmtp", "X-SMTP"],
Expand All @@ -19,4 +19,3 @@
"psr-0": {"Smtpapi": "lib/"}
}
}

11 changes: 7 additions & 4 deletions lib/Smtpapi.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
<?php

class Smtpapi {
const VERSION = '0.2.0';
class Smtpapi
{
const VERSION = '0.3.0';

public static function register_autoloader() {
public static function register_autoloader()
{
spl_autoload_register(array('Smtpapi', 'autoloader'));
}

public static function autoloader($class) {
public static function autoloader($class)
{
// Check that the class starts with 'Smtpapi'
if ($class == 'Smtpapi' || stripos($class, 'Smtpapi\\') === 0) {
$file = str_replace('\\', '/', $class);
Expand Down
Loading