How do I get these strange characters when I try to "echo" the html string?

I am sending the echo to mail function via PHP from variable that includes HTML code. The strange thing is, that this

<����}im�

shows up AFTER the string.. but I do not manipulate with it anymore. The charset of mail function (the attachment) is same as charset of HTML code.

Answers


Encoding problem, maybe it tries to display binary code?

You should use htmlentities if ou want to display HTML

// Outputs: A 'quote' is

<b>bold</b> echo

htmlentities($str);


Those characters are probably "junk" data in your string. Depending on where the string is coming from these characters could be: extra TCP data in the socket after the HTML page, or extra data in the file after the HTML page, or someone else actually put these characters in their HTML page (perhaps their file was accidentally corrupted, or for some other reason).


You could consider using the htmlMimeMail class for handling the email. So you can avoid the nasty email internals.


This is the problem I have.. I use the code from Internet source, the $body is generated invoice and this send the email.. Those characters are at the end of HTML source file but I don't understand why the hell they are there :(

$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 );

Need Your Help

Access java keystore programmatically to create SSLSocketFactory

java ssl keystore jks

I am establishing an SSL connection to a server which has enabled ssl.There is a cacerts file in my hardware's filesystem java keystore and I extracted the certificate from it using keytool &amp; I...

Make.exe / Android / Cocos-2d-x: No such file or directory

android android-ndk cocos2d-x

I'm trying to build the Android version of the latest cocos2d-x, but I get this error when trying to compile the native code: