PHP email subject encoding

If you thought that setting “Content-Type” will suffice to make your email just send away without problems, think again. The specified character encoding in “Content-Type” will only describe the character encoding of the body, not the subject itself. If the subject contains UTF-8 chars your email subject will not look as expected on the recipient. To fix this issue you will need to use the encoded-word syntax (RFC2047#section-2) with either the quoted-printable encoding or the Base64 encoding.
Here is a quick snippet on how I did it:

1
2
3
4
if (strlen($subject) != strlen(utf8_decode($subject))) //check if subject is utf-8
       fwrite($socket, 'Subject: =?UTF-8?B?'.base64_encode(html_entity_decode(utf8_encode($subject), ENT_COMPAT, "UTF-8"))."?="."\r\n".'To: <'.implode('>, <', $recipients).'>'."\r\n".$headers."\r\n\r\n".$message."\r\n");
 else
       fwrite($socket, 'Subject: '.$subject."\r\n".'To: <'.implode('>, <', $recipients).'>'."\r\n".$headers."\r\n\r\n".$message."\r\n");

This syntax uses a string of ASCII characters indicating both the original char encoding and the content-transfer-encoding used to map the bytes of the charset into ASCII characters.
The syntax is: “=?charset?encoding?encoded text?=”.

As you can see above I’m trying to see if the “subject” string contains any UTF-8, so it will encode only when necessary. The encoding check I’m doing is fairly simple, and you can also use mb_check_encoding function to do the same thing. I didn’t use it because it requires php_mbstring extension loaded, which is a non-default extension (it is not enabled by default, you must explicitly enable the module in your php.ini).

I’m using fwrite because I’m actually writing/reading directly to sockets (working on a simple SMTP client in PHP). The same rule applies for the standard email php function: the encoded-word syntax is expected for the subject or other header field values if they contain UTF-8 chars (but not for the body).
If you are not happy with the base64 encoding you can use imap_8bit function for the quoted-printable encoding, like this:

1
$subject="=?UTF-8?Q?".imap_8bit($subject)."?=";

Hope this helps. Good luck!

țepe de black friday?

Atentie la ce cumperi azi (23 noiembrie, black-friday) din Romania, “graba strica treaba”.

Reducerea era oricum seminificativa, chiar daca nu mareau pretul vechi…
Sfat: inainte sa comanzi, cauta pe site-urile de profil (gen price.ro, shopmania etc) pentru a vedea exact cat e reducerea.

Televizoare destepte – clatite nu fac, in rest cam tot ce vrei…

Ma uitam de curiozitate dupa un televizor cat de cat ok la pret, ma gandeam la un LCD sau poate chiar LED. Si cum mai uitam eu asa alene, ba in stanga, ba in dreapta, gasesc minunatia asta. Pare cel mai accesibil din categoria “Smart TV” (are si o mica reducere de 50 ron) TV LED Sony (56 cm, HD, 22EX550) cu toate cele suportate:

- 24p True Cinema
- Reducere inteligenta a zgomotului MPEG
- Rezolutie 1366 x 768
- Imagine HD
- Edge LED
- Player multimedia integrat;
- Intrare USB 2.0;
- Intrare PC (D-sub);
- Intrare video composite;
- Intrari Scart (RGB);
- 2 Porturi HDMI;
- Iesire audio digitala (optica);
- Slot card PCMCIA;
- Minijack casti;
- Greutate: 5.7kq;
etc.

Si peste toate astea mai adaugi faptul ca ti se conecteaza la retea: prin RJ45 (clasica mufa de retea, da, aia care o bagi in calculator sa ai net :-) ) sau chiar prin Wireless. De ce sa-l conectezi? ca sa ai net pe el, sa poti sa faci si tu un browsing cand nu ai nimic de vazut, sau poate sa te bagi la un mic partypoker direct de pe TV? Buna ideea dar totusi nu-i vad rostul… daca vreau browsing imi iau tableta/laptopul la butonat pentru ca mi se pare mult mai accesibila decat telecomanda.

Ce mi s-a mai parut interesant este playerul multimedia integrat, in afara faptului ca poate reda content multimedia din reteaua ta proprie, acesta mai permite si inregistrarea pe USB pentru ceea ce vizionezi la TV. O sa poti inregistra emisiunea sau meciul pe USB HDD/stick si apoi sa-l redai cand vrei. Il poti folosi si pe post de monitor pentru ca are intrare VGA si 2xHDMI. Sunetul e ok pentru un TV, 2 difuzoare x 8W (cu Dolby/Surround) eu zic ca e suficient. Diagonala 56cm, un consum de ~25W, cat un monitor… Ecranul se poate pivota in plan vertical, telecomanda are baterii de dimensiune AAA (tip R03), suport de prindere pentru cablurile din spate…

M-am convins, uite banii, unde semnez? $-)

Procesor Intel i3, i5, i7: placa video? cine mai are nevoie…

 Cu cateva luni in urma am reusit sa-mi schimb systemul complet trecand pe un procesor i5-2500K SandyBridge si, desi tinta mea nu a fost de a avea un system de gaming, am putut rula orice joc din 2008-2011 fara a avea nevoie de o placa video, totul la o calitate impresionanta, fara dead-lockuri si timp prea mult stat in loading screen-uri. Chiar nu ma asteptam sa pot juca Rage pe full graphics quality doar cu procesorul. Alaturi de jocul Rage mai adaug si Borderlands, Darksiders, Dead Island, Fear 3, Mass Effect 2, The Elder Scrolls V: Skyrim, Mafia 2, HAWX 2 si probabil multe altele. Va astept pe voi sa-mi spuneti ce ati mai putut juca doar cu noile procesorare de la Intel.

 Pe mine m-a cam lasat fara cuvinte cat de mult a putut avansa Intel cu procesoarele. Sandy Bridge-ul, numele de cod pentru noua microarhitectura de la Intel ce a fost lansata de ceva vreme, aduce integrarea nucleului grafic direct in procesor ajungand astfel la performante de necrezut ale placii grafice. Hmmm, nu e prima data cand se incearca acest lucru si cand se reuseste imbinarea a doua componente intr-una singura, dar este prima data cand se face includerea unui procesor grafic in aceeasi bucata de silicon ca si procesorul, totul fiind integrat. In plus, aceasta este prima data cand avem un procesor grafic (GPU) integrat de la Intel care intr-adevar are sens. In principiu, placile video ieftine nu isi mai au rostul, chiar nu-si au rostul, gandeste-te la faptul ca economisesti bani si nu te mai intalnesti cu situatii de genul acelora in care temperatura din carcasa devine o problema atunci cand coolerul de pe placa video incepe sa dea rateuri (sau in cazul placilor ultra ieftine cu racire pasiva ). Eliminarea placii video din sistem mi se pare un “must do” pentru cei cu buget limitat si care nu au pretentii de a se juca jocuri pe rezolutii imense si la o calitate extrema. Daca totusi ai pretentia sa te joci la o calitate maxima adauga si o placa video Gainward nVidia GeForce GTX580 si bucura-te de tehnologiile Intel la maxim:

  • Intel Turbo Boost 2.0 (mult mai agresiv decat predecesorul): redirectioneaza puterea si accelereaza performanta in mod dinamic, pentru a se potrivi nivelului de incarcare al aplicatiilor folosite.
  • Intel Hyper-Threading: poti rula simultan o multime de aplicatii desktop cu cerinte ridicate, fara incetiniri de viteza.
  • Intel HD Graphics: permite rularea fluenta a filmelor HD, la cea mai buna calitate; de asemenea, ofera capacitati 3D avansate si suport complet pentru sistemul de operare utilizat, fara necesitatea unei placi grafice dedicate.

Un procesor standard are un singur nucleu (single-core) ce “proceseaza” o singura instructiune la un moment dat. Nucleele multiple pot fi folosite pentru a rula doua programe simultan si atunci cand un program mai intensiv se executa (antivirus sau conversie video, CD ripping etc.) puteti utiliza alt nucleu pentru a rula alta aplicatie. Pentru a nu face greseala de a asocia numele procesorului cu numarul de nuclee (Intel Core 2 Duo cu 2 nuclee) iata ce avem:

Microarhitectura Sandy Bridge aduce si un nou socket pe placa de baza: Socket H2 (LGA1155). Acesta seamana cu Socket H (LGA1156), dar nu sunt compatibile. Sloturile sunt identice ca forma si dimensiune, dar nu ca layout al pinilor si cheilor de securitate.
 Sandy Bridge satisface probabil 80% din clientii care isi permit procesoarele, performanta lor fiind clar imbunatatita, in timp ce consumul si caldura degajata scad. Asta ne ofera un procesor complet, zic eu, care nu e nevoit sa faca sacrificii pentru a fi probabil cel mai bun.

Alte jocuri confirmate de voi si care sa mearga fara probleme numai cu procesorul:

Unlocking Windows Phone 7 and updating to mango (beta2)

THE GOOD NEWS

The first Windows Phone 7 jailbreak has been released along time ago and its called ChevronWP7, it has been developed by well known and respected Microsoft community enthusiasts Rafael Rivera, Long Zheng and Chris Walsh. ChevronWP7 will allow anyone to unlock a WP7 device for developing purpose, giving you the possibility to install and run your won software without a developer account.

THE BAD NEWS

ChevronWP7 works only with the first version on WP7, with your stock software (before the big copy-paste update, the NoDo-7392).

Although at beginning I was enthusiastic and ready to pay the developer account yearly fee, guess what? My country (Romania) was not an option! and that almost filled my eyes with tears (just kidding). Anyway, because I’m from a different country not “supported” by app hub, I’ve decided to go along and try to unlock my phone for learning purpose. I’ve succeed that after hours of reading and trying that, and the other thing and doing recover from backup on failure and blah, blah, blah and here I am now, with my new HTC Mozart fully unlocked and updated to the latest big update, Mango. It is surprisingly very simple to activate your phone for developing purpose, you only need to make a registry entry on your phone: DeveloperUnlockState inside HKLM\Comm\Security\LVMod and then another one to prevent Zune to lock back the phone. But how the heck you will going to do that? because is not as easy as was on older windows mobile versions ,WM5-6 or 6.5. Well, just search on xda forums and you will find your way. Let me cut it down for you in some simple steps that I did for my HTC Mozart (this works only on HTC devices): Read more »

Google+ Invites For Free: Get’em Quick!

The new Google’s social networking site is up and running in beta stage for some time now, as you expected is invitation based. Scams are all over the net trying to make a buck out of this. Try searching amazon for example, $100 for a Google+ invitation, wtf? Are you for real? Are you going to pay for that when is free and it will be made public for everyone to register, FREE? It looks like people do spend money on a simple thing that can be for free, just search for free invites and you will get a bunch of them. If you don’t believe that invitations can be free and you want to try the new Google’s project (Google+ Plus), just leave your gmail address in this post comments and you will get invited ;-)

    Notes:

  • Leave your email address in the email field of the comment or omit the “gmail.com” part of the email if you don’t want it exposed to search engines.
  • If clicking on the invitation email link “Learn more about Google+” does not allow you to register try again later, eventually will work. Good Luck!

Ia-ti un SSD, chiar merita!

Ziceam mai demult ca prefer 1TB spatiu ieftin decat un SSD, ziceam asta fara a avea experienta unui SSD. Dar acum, dupa ce am reusit sa pun mana pe un SSD si sa-l testez mai bine, imi schimb parerea total: SSD-ul isi merita investitia pe deplin! Nu am crezut ca diferenta o sa fie chiar asa de vizibila.

SSD-ul testat: OCZ OCZSSD2-1ONX32G, 32GB, SATA II
Pret: 339,00 RON (cu TVA)
System: Notebook Dell Inspiron 1520 T7500 2.2GHz, 2GB, PM346
OS: Windows 7 32bit


Cand m-am vazut cu SSD-ul in mana am realizat ca este fix identic cu HDD-ul ce tocmai il schimbasem la notebook, si cum habar n-aveam daca il pot pune la laptop am zis hai sa incerc, poate merge (evident ca mergea, doar e 2,5″, doh!). Zis si facut. Ii dau shutdown, il intorc invers, desurubez si scot hard disc-ul afara. Apoi desurubez si masca de plastic care-l tine (masca are doua suruburi pe lateral). Iau SSD-ul si-l il pun langa HDD sa le compar, ce sa vezi? Identic! Oau, am mai invatat ceva! Montez pe SSD masca (da, se pupa perfect masca pe SSD) si il bag inapoi in laptop. Ii dau drumul la laptop, intru in bios (F2) si vad ca am hdd de 32GB! tadaaa! mergeeee! Neeeext: sa instalez Windows-ul.

Bag dvd-ul cu Win7, bootez, se incarca setupul si mi-l vede ca “unpartitioned space”, fara nevoie de alte drivere. Ii dau sa se instaleze si dupa 10 minute ma trezesc pe desktop. Perfect! Asta a fost tot. Te asteptai sa ma plang ca nu a mers, ca probabil nu l-a vazut la setup si asa mai departe? Nu, pentru ca totul a decurs normal si rapid, cel mai mult a stat la copierea de pe DVD, in rest totul a mers uns cu delma :-)

Dupa ceva timp si aplicatii instalate trag concluzia ca timpul de acces este instant, totul se incarca foarte rapid. Incepand de la logo-ul windows-ului care apare pe ecran trec numai 2-3 secunde si deja in secunda urmatoare ai desktop-ul si toate aplicatiile incarcate. Modelul de l-am avut suporta TRIM si este un SSD MLC (Multi Level Cell), o varianta mai ieftina si putin mai slaba (teoretic) decat modelele SLC (Single Level Cell).

Mai jos am sa pun rezultatele unor aplicatii de testare si ce tweak-uri am facut…
Read more »

SSD sau HDD in raid0?

Ma bate gandul sa trec pe windows 7, am deja laptopul pe win7 de ceva vreme dar cu desktopul, unde-mi “intretin” proiectele, sunt tot pe XP. Daca tot trec pe win7 m-am gandit sa-mi fac un upgrade la hhd-uri, si daca tot au aparut tehnologii mai noi ma gandeam la un SSD (solid-state drive) de pe care sa ruleze windows-ul impreuna cu cele mai folosite applicatii (Borlandul, Visual Studio-ul etc). Marele dezavantaj al ssd-urilor este pretul destul de piperat. Apoi urmeaza faptul ca au o viata mai scurta, au un ciclu de scriere/citire limitat comparat cu hardurile pe platane, care poate tine mai mult de 10 ani fara probleme mecanice. Si din cate am inteles daca intervine vre-o problema mecanica la ssd o sa-ti pierzi datele complet. Da, este adevarat, tehnologie noua flash-based, fara parti mecanice – platane, fara zgomot (no spin-up), seek time constant si performantele nu scad daca hardul este plin, rezistenta mai mare la soc, temperatura si virbratii etc… Dar totusi un Flash SSD Kingston SNV425-S2BD/64GB ajunge la 600ron. Da, 600ron doar pentru 64gb? Oau… oare merita investitia asta? Sa dai 100 ron pe 10gb de spatiu? N-as prea crede, cred ca singurul update pe care am sa-l fac la hdd-uri este sa-mi iau doua bucati HDD Western Digital Caviar SE16 500GB, 7200rpm, 16MB, SATA2 (169,00 RON bucata), le pun in raid0 si ma aleg cu 1TB de spatiu si performante aproape asemanatoare cu un ssd. Prefer spatiul in plus, un pret mult mai accesibil si siguranta datelor cat de cat mai ridicata, inca nu am asa mare incredere in ssd-uri. Poate cu timpul se va avansa mai mult si intradevar era hard discului o sa apuna si viitorul o sa apartina SSD-urilor.

Subs Grabber project moved

  I’m not maintaining the Subs Grabber project anymore, all projects copyrights and feature updates will be released from now here. As you can see Subs Grabber sources have been sold, and it goes shareware from now on. I’m still using it for my personal use, is still a great subtitles tool but I don’t have sufficient time for this project, I’ve found an old friend who will take subs grabber to the next level, hope to succeed because it looks greater and useful with every release, I’m proud I’ve managed to start it, to bad I didn’t succeed in keep it here.

ps: Happy valentines day! :X

My Tweet Tools

  • BsTweet - BsPlayer plugin to automatically send a Twitter status update with your movie name when you play it. (nice one!)
  • TwitBin – a firefox extension that allows you to keep up with all of your Twitter conversations right from your browser sidebar. Send messages, receive messages, share links
  • Seesmic for Windows – Fully functional Twitter integration
    View aggregated Home, Replies, Private and Sent columns. Manage and post from multiple twitter accounts, create unlimited columns for your saved searches and lists created from Twitter.
  • Twitme – wordpress plugin to automatically post your new posts on the twitter.