Skip to content

Commit

Permalink
Merge pull request #293 from mailjet/DE-1292-support-emoji-for-php-wr…
Browse files Browse the repository at this point in the history
…appers

UTF 8  string notation for subject. Support emoji
  • Loading branch information
oleksandr-mykhailenko authored Jun 23, 2024
2 parents 9708fc6 + b027739 commit 04c0a3c
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
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));
}
}

0 comments on commit 04c0a3c

Please sign in to comment.