-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #293 from mailjet/DE-1292-support-emoji-for-php-wr…
…appers UTF 8 string notation for subject. Support emoji
- Loading branch information
Showing
2 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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! | ||
|
This file contains 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 characters
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)); | ||
} | ||
} |