【发布时间】:2013-09-21 20:06:01
【问题描述】:
对不起我的英语。
我用php建立一个链接。 我通过电子邮件发送。 有时链接(在电子邮件中)已损坏。
当我点击(或复制到浏览器)时已在随机位置插入了一个空格。
有什么想法吗?
生成邮件,代码如下:
$url="www.example.com/dir/subdir/page.php?param1=$p1¶m2=$p2¶m3=$p3[...]¶m20=$p20";
[...]
$body .= "<td><a href=\"$url\">";
$body .= htmlentities($url,ENT_NOQUOTES,'ISO-8859-1');
$body .= "</a></td>";
[...]
$headers = "From: $companyName < $companyMail > \r\n";
$headers .= "Reply-To: $companyMail \r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1 ";
$headers .= "Content-Type: text/html; charset=ISO-8859-1";
$headers .= "MIME-Version: 1.0 ";
mail($client, "Confirmaton", $body, $headers);
page.php 上的示例接收参数
代码:
echo "<pre>Request:<br>";
print_r($_REQUEST);
echo "</pre><br>";
exit;
case OK:
Request:
Array
(
[p1] => value1
[p2] => value2
[p3] => value3
[p3] => value5
[p4] => value6
[p5] => value7
(...)
[p20] => value20
)
Error1 (link with space in value)
Request:
Array
(
[p1] => value1
[p2] => val ue2
[p3] => value3
[p3] => value5
[p4] => value6
[p5] => value7
(...)
[p20] => value20
)
Error2 (link with space in variable)
Request:
Array
(
[p1] => value1
[p2] => value2
[p_3] => value3
[p3] => value5
[p4] => value6
[p5] => value7
(...)
[p20] => value20
)
【问题讨论】:
-
你能给我们一个网址的例子吗?
-
我怀疑你需要
urlencode()而不是htmlentities()。 -
可能无法修复,但您需要添加
http://尝试$url="http://www.example.com...,因为该链接在大多数电子邮件客户端中无法点击。 -
大多数邮件客户端会在一定数量的字符(例如 80 个字符)之后插入换行符。如果您将换行符复制并粘贴到浏览器栏中,它将变为空格。
-
我在 url 的开头添加:http://,像这样的 urlencode ?param1=".urlencode($p1)."¶m2=".urlencode($p2)." 和 style= \"white-space:nowrap;\" 在包含链接的
处。似乎在一些测试中工作过