Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UTF 8 string notation for subject. Support emoji #293

Merged
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
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,45 @@ $response = $mj->post(Resources::$SmsSend, ['body' => $body]);
$response->success() && var_dump($response->getData());
```


### Send request with supporting emojis in the subject

```php
require 'vendor/autoload.php';

use \Mailjet\Resources;

$mj = new \Mailjet\Client(
'xxx',
'xxx',
true,
);

try {
$subject = \Mailjet\Utility\StringUtility::utfStringNotation("This is subject with emoji 🤑" );

$body = [
'Locale' => "en_US",
'Sender' => "[email protected]",
'SenderEmail' => "[email protected]",
'Subject' => $subject,
'TemplateID' => 12345,
'ContactsListID' => 12345,
'Title' => "Emoji Test" . time(),

];
$response = $mj->post(
Resources::$Campaigndraft,
[
'body' => $body,
]
);
print_r($response->getData());
} catch (Throwable $throwable) {
print_r($throwable->getMessage());
}
```

## Contribute

Mailjet loves developers. You can be part of this project!
Expand Down
16 changes: 16 additions & 0 deletions src/Mailjet/Utility/StringUtility.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Mailjet\Utility;

final class StringUtility
{
/**
* This method is used to encode a string to UTF-8 notations for using in Subject.
* @param string $string
* @return string
*/
public static function utfStringNotation(string $string): string
{
return sprintf('=?UTF-8?B?%s?=', base64_encode($string));
}
}