0

我正在通过 PHP 从包含 HTML 代码的变量将回显发送到邮件函数。奇怪的是,这

<����}im�

出现在字符串之后..但我不再使用它了。邮件功能(附件)的字符集与 HTML 代码的字符集相同。

4

4 回答 4

2

编码问题,也许它试图显示二进制代码?

如果你想显示 HTML,你应该使用 htmlentities

// 输出:'quote' 是

<b>粗体</b>回显

htmlentities($str);

于 2008-11-18T21:51:45.367 回答
0

这些字符可能是字符串中的“垃圾”数据。根据字符串的来源,这些字符可能是:HTML 页面之后的套接字中的额外 TCP 数据,或者 HTML 页面之后的文件中的额外数据,或者其他人实际上将这些字符放在他们的 HTML 页面中(可能是他们的文件被意外损坏或出于其他原因)。

于 2008-11-18T21:52:33.620 回答
0

您可以考虑使用htmlMimeMail类来处理电子邮件。所以你可以避免讨厌的电子邮件内部。

于 2008-11-19T02:49:44.113 回答
0

这就是我遇到的问题..我使用来自 Internet 源的代码,$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 );
于 2008-11-20T17:12:31.313 回答