Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
4kimov committed Mar 24, 2024
1 parent 59c9378 commit 8d91915
Show file tree
Hide file tree
Showing 18 changed files with 489 additions and 25 deletions.
16 changes: 12 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
# CHANGELOG

**v0.1.0-alpha.3:**
## v0.1.0-alpha.4:

- New social icons: `Service::MASTODON` and `Service::RSS`
- New store badges component
- New QR code component
- New signature component
- New [examples](examples)

## v0.1.0-alpha.3:
- `README.md`: notice about test mode
- Support for test mode logging

**v0.1.0-alpha.2:**
## v0.1.0-alpha.2:
- `README.md` cleanup (listing of components)
- `Image` component now requires only `src`; the other params are optional
- `ViewInBrowser` component has changed: text is optional

**v0.1.0-alpha.1:**
## v0.1.0-alpha.1:
- Introduced `CHANGELOG.md`
- Introduced new services as social icons:
- `Service::PHONE` (converts into a link with `tel:` prefix)
Expand All @@ -24,5 +32,5 @@
- `Service::THREADS`
- `Service::TELEGRAM`

**v0.1.0-alpha.0:**
## v0.1.0-alpha.0:
- Initial implementation
91 changes: 89 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,7 @@ Link component adds an anchor tag. This is the same as a text component with the

```php
Content::builder()
->link("Confirm Email", "https://example.com/confirm?token=XYZ") // or...
->text("[Confirm Email](https://example.com/confirm?token=XYZ)")
->link("Confirm Email", "https://example.com/confirm?token=XYZ")
->build();
```

Expand Down Expand Up @@ -252,6 +251,8 @@ Content::builder()
new SocialItem(Service::SNAPCHAT, "Username"),
new SocialItem(Service::THREADS, "Username"),
new SocialItem(Service::TELEGRAM, "Username"),
new SocialItem(Service::MASTODON, "@[email protected]"),
new SocialItem(Service::RSS, "https://example.com/blog"),
])
->build();
```
Expand All @@ -271,6 +272,92 @@ Content::builder()
->build();
```

</details>
<details><summary>Store Badges</summary>

Link to your mobile apps via store badges:

```php
Content::builder()
->store_badges([
new StoreBadgeItem(StoreBadge::APP_STORE, "https://apps.apple.com/us/app/example/id1234567890"),
new StoreBadgeItem(StoreBadge::GOOGLE_PLAY, "https://play.google.com/store/apps/details?id=com.example"),
new StoreBadgeItem(StoreBadge::MICROSOFT_STORE, "https://apps.microsoft.com/detail/example"),
])
->build();
```

</details>
<details><summary>QR Code</summary>

You can also generate QR codes on the fly. They will be shown as images inside the email.

Here are all the supported data types:

```php
// url
Content::builder()
->qr_code("https://example.com")
->build();

// email
Content::builder()
->component(QrCode::email("[email protected]"))
->build();

// phone
Content::builder()
->component(QrCode::phone("123-456-7890"))
->build();

// sms / text message
Content::builder()
->component(QrCode::sms("123-456-7890"))
->build();

// geo coordinates
Content::builder()
->component(QrCode::coordinates(37.773972, -122.431297))
->build();

// crypto address (for now only Bitcoin and Ethereum are supported)
Content::builder()
->component(QrCode::cryptocurrencyAddress(Cryptocurrency::BITCOIN, "1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa"))
->build();

// you can also encode any binary data
Content::builder()
->component(new QrCode(implode(array_map(function($byte) { return chr($byte); }, [1, 2, 3]))))
->build();
```

</details>
<details><summary>Signature</summary>

Generated signatures can be added to your emails to give a bit of a personal touch. This will embed an image with your custom text using one of several available fonts:

```php
// signature with a default font
Content::builder()
->signature("John Smith")
->build();

// signature with a custom font
Content::builder()
->component("John Smith", SignatureFont::REENIE_BEANIE)
->build();
```

These are the available fonts:

- `SignatureFont::REENIE_BEANIE` [preview →](https://fonts.google.com/specimen/Reenie+Beanie)
- `SignatureFont::MEOW_SCRIPT` [preview →](https://fonts.google.com/specimen/Meow+Script)
- `SignatureFont::CAVEAT` [preview →](https://fonts.google.com/specimen/Caveat)
- `SignatureFont::ZEYADA` [preview →](https://fonts.google.com/specimen/Zeyada)
- `SignatureFont::PETEMOSS` [preview →](https://fonts.google.com/specimen/Petemoss)

Signature should not exceed 64 characters. Only alphanumeric characters and most common symbols are allowed.

</details>

---
Expand Down
23 changes: 14 additions & 9 deletions examples/confirm_email.php → examples/feedback.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Templateless\EmailAddress;
use Templateless\Templateless;
use Templateless\Collection;
use Templateless\Theme;
use Templateless\Components\SocialItem;
use Templateless\Components\Service;

Expand All @@ -24,33 +25,37 @@
}

$header = Collection::builder()
->text('# ExampleApp')
->image('https://templateless.net/myco.webp', null, 100, null, 'MyCo')
->build();

$footer = Collection::builder()
->socials([
new SocialItem(Service::TWITTER, "ExampleApp"),
new SocialItem(Service::GITHUB, "ExampleApp"),
new SocialItem(Service::TWITTER, 'MyCo'),
new SocialItem(Service::GITHUB, 'MyCo'),
])
->link('Unsubscribe', 'https://example.com/unsubscribe?id=123')
->build();

$content = Content::builder()
->theme(Theme::SIMPLE)
->header($header)
->text('Hello world')
->text("Hey Alex,")
->text("I'm Jamie, founder of **MyCo**.")
->text("Could you spare a moment to reply to this email with your thoughts on our service? Your feedback is invaluable and directly influences our improvements.")
->text("When you hit reply, your email will go directly to me, and I read each and every one.")
->text("Thanks for your support,")
->signature("Jamie Parker")
->text("Jamie Parker\n\nFounder @ [MyCo](https://example.com)")
->footer($footer)
->build();

$email = Email::builder()
->to(new EmailAddress($email_address))
->subject("Confirm your email")
->subject("Thoughts on service?")
->content($content)
->build();

$templateless = new Templateless($api_key);
$result = $templateless->send($email);

var_dump($result);
$templateless->send($email);
} catch (\Exception $e) {
echo $e;
}
73 changes: 73 additions & 0 deletions examples/qr_code.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php

require_once './vendor/autoload.php';

use Templateless\Content;
use Templateless\Email;
use Templateless\EmailAddress;
use Templateless\Templateless;
use Templateless\Collection;
use Templateless\Theme;
use Templateless\Components\SocialItem;
use Templateless\Components\Service;
use Templateless\Components\StoreBadgeItem;
use Templateless\Components\StoreBadge;

try {
$api_key = $env["TEMPLATELESS_API_KEY"] ?? getenv("TEMPLATELESS_API_KEY");
if (!isset($api_key) || $api_key == '') {
echo "Set TEMPLATELESS_API_KEY to your Templateless API key";
exit;
}

$email_address = $env["TEMPLATELESS_EMAIL_ADDRESS"] ?? getenv("TEMPLATELESS_EMAIL_ADDRESS");
if (!isset($email_address) || $email_address == '') {
echo "Set TEMPLATELESS_EMAIL_ADDRESS to your own email address";
exit;
}

$header = Collection::builder()
->image('https://templateless.net/myco.webp', null, 100, null, 'MyCo')
->build();

$app_store_link = "https://apps.apple.com/us/app/example/id1234567890";
$google_play_link = "https://play.google.com/store/apps/details?id=com.example";

$footer = Collection::builder()
->store_badges([
new StoreBadgeItem(StoreBadge::APP_STORE, $app_store_link),
new StoreBadgeItem(StoreBadge::GOOGLE_PLAY, $google_play_link),
])
->socials([
new SocialItem(Service::TWITTER, 'MyCo'),
new SocialItem(Service::GITHUB, 'MyCo'),
])
->build();

$content = Content::builder()
->theme(Theme::SIMPLE)
->header($header)
->text("Hey Alex,")
->text("Thank you for choosing MyCo! To get started with our mobile experience, simply pair your account with our mobile app.")
->text("Here's how to do it:")
->text(implode("\n", [
"1. Download the MyCo app from the [App Store]($app_store_link) or [Google Play]($google_play_link).",
"1. Open the app and select _Pair Device_.",
"1. Scan the QR code below with your mobile device:",
]))
->qr_code("https://example.com/qr-code-link")
->text("Enjoy your seamless experience across devices!")
->footer($footer)
->build();

$email = Email::builder()
->to(new EmailAddress($email_address))
->subject("How to Pair Device")
->content($content)
->build();

$templateless = new Templateless($api_key);
$templateless->send($email);
} catch (\Exception $e) {
echo $e;
}
14 changes: 6 additions & 8 deletions examples/simple.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,18 @@
exit;
}

$content = Content::builder()
->text("Hello world")
->build();

$email = Email::builder()
->to(new EmailAddress($email_address))
->subject("Hello")
->content($content)
->content(
Content::builder()
->text("Hello world")
->build()
)
->build();

$templateless = new Templateless($api_key);
$result = $templateless->send($email);

var_dump($result);
$templateless->send($email);
} catch (\Exception $e) {
echo $e;
}
64 changes: 64 additions & 0 deletions examples/verification.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

require_once './vendor/autoload.php';

use Templateless\Content;
use Templateless\Email;
use Templateless\EmailAddress;
use Templateless\Templateless;
use Templateless\Collection;
use Templateless\Theme;
use Templateless\Components\SocialItem;
use Templateless\Components\Service;

try {
$api_key = $env["TEMPLATELESS_API_KEY"] ?? getenv("TEMPLATELESS_API_KEY");
if (!isset($api_key) || $api_key == '') {
echo "Set TEMPLATELESS_API_KEY to your Templateless API key";
exit;
}

$email_address = $env["TEMPLATELESS_EMAIL_ADDRESS"] ?? getenv("TEMPLATELESS_EMAIL_ADDRESS");
if (!isset($email_address) || $email_address == '') {
echo "Set TEMPLATELESS_EMAIL_ADDRESS to your own email address";
exit;
}

$header = Collection::builder()
->image('https://templateless.net/myco.webp', null, 100, null, 'MyCo')
->build();

$footer = Collection::builder()
->text("If you did not sign up for a MyCo account, please ignore this email.\nThis link will expire in 24 hours.")
->socials([
new SocialItem(Service::TWITTER, 'MyCo'),
new SocialItem(Service::GITHUB, 'MyCo'),
])
->link('Unsubscribe', 'https://example.com')
->build();

$verify_email_link = 'https://example.com/verify?token=ABC';

$content = Content::builder()
->theme(Theme::SIMPLE)
->header($header)
->text("Hi there,")
->text("Welcome to **MyCo**! We're excited to have you on board. Before we get started, we need to verify your email address.")
->text("Please confirm your email by clicking the button below:")
->button("Verify Email", $verify_email_link)
->text("Or use the link below:")
->link($verify_email_link, $verify_email_link)
->footer($footer)
->build();

$email = Email::builder()
->to(new EmailAddress($email_address))
->subject("Confirm your email")
->content($content)
->build();

$templateless = new Templateless($api_key);
$templateless->send($email);
} catch (\Exception $e) {
echo $e;
}
Loading

0 comments on commit 8d91915

Please sign in to comment.