Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This may or may not be useful, but I think I appreciate your pain when it comes to handling mailing errors in PHP, so I thought I'd at least try help get this thread going!</p> <p>One thing I didn want to ask was are you sure that the values being posted coming in in UTF-8 encoding? Also, I can't help but think the new-line characters might be causing some funky behaviour, so why not try something like this instead (where applicable):</p> <pre><code>line = "\r\n"; $value = str_replace('\n', $line, $value); </code></pre> <p>Notice the <strong>double quotes</strong> around the new-line character I put in for $line...I'm assuming that the first '\n' above is physically being put into the value and needs replacing? Otherwise, especially with plain-text e-mail, you shouldn't have to worry about parsing for those new-line characters, just feed it straight through to the mail message.</p> <p><em><strong>EDIT:</em></strong></p> <p>Not sure if this will help, but after running the most basic mail send functions using <a href="http://framework.zend.com/manual/en/zend.mail.html" rel="nofollow">Zend's mail libraries</a> - UTF-8 and base64 encoding - and inspecting the source of the message that came through, this is basically all you need for your plain-text mail, given this as the message:</p> <pre><code>$message = "This is a\r\ntest message"; </code></pre> <p>...the mail source snippet will be:</p> <pre><code>Date: Sun, 23 Oct 2011 16:24:16 +0300 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: base64 Content-Disposition: inline MIME-Version: 1.0 VGhpcyBpcyBhDQp0ZXN0IG1lc3NhZ2U= </code></pre> <p><em><strong>EDIT #2:</em></strong></p> <p>Ok, I think I've finally figured out something that will help, although this will only help when sending <strong>HTML</strong> mail messages with Czech special characters. The problem doesn't seem to be as much to do with the character encoding as the HTML special characters (well, for me anyways!), so the following code seemed to yield the original text just fine in my trusty Firefox web browser:</p> <pre><code>&lt;?php // original message... $message = "To je nějaký ukázkový text.\r\nTento text je na dalším řádku."; // convert as many characters as possible in PHP &lt; 5.4... $message = htmlentities($message, ENT_QUOTES, 'UTF-8'); // I suspect this next line will work for all characters in PHP &gt;= 5.4... // $message = htmlentities($message, ENT_SUBSTITUTE, 'UTF-8'); // if not all characters are being converted, plug the missing ones in here // with their relevant codes... $missing_characters = array ( 'ě' =&gt; '&amp;#283', 'ř' =&gt; '&amp;#345;' ); // heavy function, but I wasn't trying to be efficient ;) foreach ($missing_characters as $char =&gt; $code) $message = str_replace($char, $code, $message); // this should give you the original string in a browser... echo $message; ?&gt; </code></pre> <p><em><strong>EDIT #3:</em></strong></p> <p>And finally, to achieve the same result with text visible in <strong>plain-text</strong> mail messages is a lot simpler. Just base64 encode the message, set the appropriate headers, and use <a href="http://php.net/manual/en/function.mail.php" rel="nofollow">PHP's mail</a> function to do the rest. Here's how I got it working:</p> <pre><code>// original message... $message = "To je nějaký ukázkový text.\r\nTento text je na dalším řádku."; $message = base64_encode($message); // headers... $headers = ""; $headers .= "From: your-email@domain.com\r\n"; $headers .= "Content-Type: text/plain; charset=UTF-8\r\n"; $headers .= "Content-Transfer-Encoding: base64\r\n"; $headers .= "MIME-Version: 1.0"; mail("destination-email@domain.com", "Subject Here", $message, $headers); </code></pre> <p>Hope this helps! :)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload