Skip to content

Instantly share code, notes, and snippets.

@sebm
Created January 25, 2011 08:52
Show Gist options
  • Save sebm/794680 to your computer and use it in GitHub Desktop.
Save sebm/794680 to your computer and use it in GitHub Desktop.
Explanation of UTF-8 header testing for Symfony / Swift Mailer
<?php
$expectedHeaderMessage = Swift_Message::newInstance()
->setSubject('Información')
->setCharset('utf-8')
;
$msgString = $expectedHeaderMessage->toString();
/*
echo $msgString:
Message-ID: <1295950012.4d3ea0bcbcb3a@swift.generated>
Date: Tue, 25 Jan 2011 10:06:52 +0000
Subject: =?utf-8?Q?Informaci=C3=B3n?=
From:
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
*/
<?php
$matches = array();
$pattern = '/\nSubject: ([A-z0-9\-\?\= ]*).*\n/';
preg_match($pattern, $msgString, $matches);
<?php
$browser->
info("The UTF-8 header is as we expect it to be")->
with('mailer')->begin()->
checkHeader('Subject', '/'.preg_quote($matches[1]).'/')->
end()
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment