“ echo”を試みたときに、これらの奇妙な文字を取得するにはどうすればよいですか? html文字列?
質問
HTMLコードを含む変数からPHP経由でメール機能にエコーを送信しています。奇妙なことは、これ
<����}im�
は文字列の後に表示されます。メール機能の文字セット(添付ファイル)は、HTMLコードの文字セットと同じです。
解決
エンコードの問題、おそらくバイナリコードを表示しようとしていますか?
HTMLを表示する場合は、htmlentitiesを使用する必要があります
//出力:「引用」は
&lt; b&gt;太字&lt; / b&gt;エコー
htmlentities($ str);
他のヒント
これらの文字はおそらく「ジャンク」です;文字列のデータ。文字列がこれらの文字から来る場所に応じて:HTMLページの後のソケットの追加TCPデータ、またはHTMLページの後のファイルの追加データ、または他の誰かが実際にこれらの文字をHTMLページ(おそらくファイル誤って破損したか、他の何らかの理由で)。
htmlMimeMail クラスを使用してメールを処理することを検討できます。そのため、厄介な電子メールの内部を回避できます。
これは私が抱えている問題です。インターネットソースのコードを使用し、$ bodyが請求書を生成し、これが電子メールを送信します。これらの文字はHTMLソースファイルの最後にありますが、なぜ地獄彼らはそこにいる:(
$to = 'email@email.com';
$subject = 'Invoice';
$random_hash = md5(date('r', time()));
$headers = "From: mymail@mymail.com\r\nReply-To: webmaster@example.com";
$headers .= "\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\"";
$body=rtrim(chunk_split(base64_encode($body)));
//define the body of the message.
ob_start(); //Turn on output buffering
?>
--PHP-mixed-<?php echo $random_hash; ?>
Content-Type: multipart/alternative; boundary="PHP-alt-<?php echo $random_hash; ?>"
--PHP-alt-<?php echo $random_hash; ?>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit
Hello World!!!
This is simple text email message.
--PHP-alt-<?php echo $random_hash; ?>
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: 7bit
Text Emailu.
--PHP-alt-<?php echo $random_hash; ?>--
--PHP-mixed-<?php echo $random_hash; ?>
Content-Type: text/html; charset="UTF-8"; name="faktura.html"
Content-Transfer-Encoding: base64
Content-Disposition: attachment
<?php echo htmlentities($body); ?>
--PHP-mixed-<?php echo $random_hash; ?>--
<?php
//copy current buffer contents into $message variable and delete current output buffer
$message = ob_get_clean();
//send the email
$mail_sent = @mail( $to, $subject, $message, $headers );
所属していません StackOverflow