我通过php mail函数向客户端发送html电子邮件。而&以粗体显示的标志在电子邮件替换中产生问题%20类似于我的ID中的字符,如下面(粗体)。
http://test.com/test-page.php?id=abcd**!**1234&cat_id=23
以下是我的代码。 $ to ='test@abc.com';
// 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 <test@abc.com>' . "\r\n";
$headers .= 'From: test user <no-reply@test.com>' . "\r\n";
// Mail it
mail($to, $subject, $message, $headers);
发送邮件后我收到了!和%20喜欢电子邮件中的字符。 我也试过&amp;除了&amp;在电子邮件中,但仍然没用!在我的电子邮件中添加html。
答案 0 :(得分:0)
尝试在传入参数上运行urldecode()
。例如:
$id = urldecode( $_GET['id'] );
答案 1 :(得分:0)
我认为您应该对电子邮件中的URL进行编码。另外,你可能有一个不推荐的magic_quotes_gpc“on”。
我总是使用PHPMailer,它可以节省大量工作并帮助解决这些问题
答案 2 :(得分:0)
试试这个:
$toName = 'test';
$toAddress = 'test@abc.com';
$fromName = 'test user';
$fromAddress = 'no-reply@test.com';
// 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 & 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);
答案 3 :(得分:0)
我将phpmailer上的编码设置更改为使用
使用base64编码$ mail-&gt;编码=“ base64 ”
这解决了我的问题。
由于HTML邮件的问题超过长度998或者我得到了上述解决方案。 :)