HTML 문자열을“에코”하려고 할 때이 이상한 캐릭터를 어떻게 얻습니까?

StackOverflow https://stackoverflow.com/questions/300259

  •  08-07-2019
  •  | 
  •  

문제

HTML 코드가 포함 된 변수에서 PHP를 통해 Echo를 메일 함수로 보내고 있습니다. 이상한 점은 이것입니다

<����}im�

문자열 이후에 나타납니다. 그러나 나는 더 이상 그것을 조작하지 않습니다. 메일 함수 (첨부 파일)의 숯은 HTML 코드의 charset과 동일합니다.

도움이 되었습니까?

해결책

인코딩 문제, 아마도 이진 코드를 표시하려고할까요?

ou html을 표시하려면 htmlentities를 사용해야합니다.

// 출력 : '인용'은입니다

u003Cb>대담한u003C/b> 에코

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 );
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top