2011-09-30 52 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自动urldecodes在'$ _GET'参数),这将是一个问题更好地找到并修复此问题... – DaveRandom

+0

没有用处?id = 83f428239f!%20f3e338d02779a25e0bd641&cat_id = 10 – jit

0

我想你应该在电子邮件上编码URL。另外,你可能有magic_quotes_gpc“on”,这是不推荐的。

我总是用PHPMailer的,这样可以节省大量的工作,对这些问题有助于

+0

与phpmailer相同的问题...... – 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);