title: insert UTF-8 characters into sql server 2008 table
body: <p>I'm inserting an email content text as UTF-8 string using php into an SQL server 2008 database table and it is working fine except one specific email.</p>
  
  <p>The INSERT command fails with this error:</p>
  
  <blockquote>
    <p>An error occurred translating the query string to UTF-16: No mapping for the Unicode character exists in the target multi-byte code page.</p>
  </blockquote>
  
  <p>The text that causes it is an extension text of a phone number:</p>
  
  <p><img src="https://i.stack.imgur.com/82gdu.jpg" alt="enter image description here"></p>
  
  <p>this "xF7" that supposed to be +91-98XXXXXXX (i added the XX) must have turned into UTF-16 or something?</p>
  
  <p>before insert into the database I did a UTF-8 check using mb_detect_encoding:</p>
  
  <pre><code>$HTMLencode = mb_detect_encoding(HTMLString, mb_detect_order(), true); 
  </code></pre>
  
  <p>$PLAINencode = mb_detect_encoding(PLAINString, mb_detect_order(), true);</p>
  
  <p>as you can see I even take under consideration a "multipart email" - part of HTML and a part of PLAIN text.
  both checks return <strong>UTF-8</strong> (which means the "xF7" fooled me.. :))</p>
  
  <p>I also did iconv() using UTF-8//IGNORE in order to ignore invalid characters,
  nothing helps, how do I solve this in php?</p>
  
  <p>The code above works fine for 99% of the emails except that one special one that raise this error.</p>