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

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

<    }im 

      

appears after the line .. but I'm not manipulating it anymore. The encoding of the mail function (attachment) is similar to the encoding of the HTML code.

0


source to share


4 answers


Encoding problem, maybe it is trying to display binary?

You have to use htmlentities if ou wants to render HTML



// Outputs: "quote" -

<b> bold </b> echo

htmlentities ($ string);

+2


source


These characters are probably "unwanted" data in your string. Depending on where the string comes from those characters, it 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 puts these characters in their HTML page (maybe their file was accidentally damaged or for some other reason).



0


source


You can use the htmlMimeMail class to handle email. This way, you can avoid annoying internal emails.

0


source


This is the problem I am facing. I am using code from an internet source, $ body is the generated invoice and this sends an email. These characters are at the end of the 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 );

      

0


source







All Articles