2011-09-30 6 views
0

나는 PHP 메일 기능을 통해 클라이언트에게 html 전자 메일을 보내고 있습니다. & 기호가 굵게 표시되어 이메일 교체시 문제가 발생합니다! % 20 아래 (굵은 글씨)와 같은 내 ID 내의 문자와 비슷한.태그 값에 대한 html 전자 메일 문제

http://test.com/test-page.php?id=abcd**!**1234&cat_id=23 

아래 코드는 제 코드입니다. $ to = '[email protected]';

// subject 
$subject = 'test'; 

//message 
$message.='<html><head><meta charset="UTF-8" /></head><body><p><a href="http://test.com/test-page.php?id=abcd1234&cat_id=23" target="_blank">Wine **&** Dine Offers</a></p></body></html>'; 

// To send HTML mail, the Content-type header must be set 
$headers = 'MIME-Version: 1.0' . "\r\n"; 
$headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n"; 

// Additional headers 
$headers .= 'To: test <[email protected]>' . "\r\n"; 
$headers .= 'From: test user <[email protected]>' . "\r\n"; 

// Mail it 
mail($to, $subject, $message, $headers); 

내가 메일을 보낸 후! % 20은 이메일의 문자와 비슷합니다. 이메일에 &을 제외하고 &을 시도했지만 아직 사용하지 않았습니다! 내 이메일 html 내에 추가.

답변

0

들어오는 매개 변수에 urldecode()을 실행 해보십시오. 예 :

$id = urldecode($_GET['id']); 
+0

동의하지만,이 매개 변수가 이중 인코딩 (PHP는 자동으로 $ _GET''의 매개 변수를 urldecodes 때문에)하고있을 것이다지고, 이에 클라이언트 측에서 문제가 필요한 경우 이 문제를 찾아 수정하는 것이 더 좋습니다 ... – DaveRandom

+0

사용하지 않음? id = 83f428239f! % 20f3e338d02779a25e0bd641 & cat_id = 10 – jit

0

전자 메일에 URL을 인코딩해야한다고 생각합니다. 게다가 magic_quotes_gpc를 "on"으로 설정하는 것이 좋습니다. 난 항상 PHPMailer를 사용

, 그것은 많은 작업을 저장하고 이러한 문제에 도움이

+0

phpmailer same issue ...... – jit

0

이 시도 :

$toName = 'test'; 
$toAddress = '[email protected]'; 

$fromName = 'test user'; 
$fromAddress = '[email protected]'; 

// subject 
$subject = 'test'; 

// URL for link 
// this should have any URL encoded characters literally in the string 
$url = 'http://test.com/test-page.php?id=abcd1234&cat_id=23&msg=URL%20encode%20this%20string'; 

// HTML for message 
// Call htmlspecialchars() on anything that may need it (like the URL) 
$messageHTML = '<html><head><meta charset="UTF-8" /></head><body><p><a href="'.htmlspecialchars($url).'" target="_blank">Wine &amp; Dine Offers</a></p></body></html>'; 

// Text version of message 
// Remember, not everyone has an HTML email client! 
$messageText = "Wine & Dine Offers: $url"; 

// Build a multipart MIME message 
$boundary = '------'.md5(microtime()).'------'; 
$body = 
"This is a multipart message in MIME format.\r\n" 
."$boundary\r\n" 
."Content-Type: text/plain\r\n" 
."\r\n" 
."$messageText\r\n" 
."$boundary\r\n" 
."Content-Type: text/html; charset=UTF-8\r\n" 
."\r\n" 
."$messageHTML\r\n" 
."--$boundary"; 

// To send HTML mail, the Content-type header must be set correctly 
$headers = "MIME-Version: 1.0\r\n"; 
$headers .= "Content-type: multipart/alternative; boundary=\"$boundary\"\r\n"; 

// Additional headers 
// the To: header will be set by mail() and is not required here 
$headers .= "From: $fromName <$fromAddress>\r\n"; 

// Mail it 
mail("$toName <$toAddress>", $subject, $body, $headers); 
관련 문제