我正在PHP程序中构建一个'mailto‘HTML元素,构建的代码如下所示:
<a href="mailto:some.one@some.where.com
?Subject=CA-7%20graphing%20tool%20error report
&body=Problem with graph http://mcz:51019/noSecurePhp/graphBuildTest.php?startJobname=PE2300DY&endJobnames=&jobMask=&collapseJobnames=&searchDepth=1&schedId=001&custSchedule=&cpColour=%23ffff00&cpStartEndColour=%23ff0000&grpBySuite=on&maxNodes=500&ranksep=0.5&nodesep=0.25&layout=dot&splines=spline&rankDir=TB&graphStyle=Full&bgColour=%23a8a8a8&nodeColour=%23ffc68c&fontColour=%23000000&nodeStyle=filled&penWidth=3%20Issue description :" target="_blank" class="btn btn-danger">Send Bug report</a>按钮看起来很好,当我将鼠标悬停在它上面时,状态栏中显示的URL看起来也很好,尽管“&”只显示为“&”,即URL看起来是正确的。
当我点击按钮时,我收到了一封新的电子邮件,邮件的地址和主题都是正确的,但正文只是:
Problem with graph http://mcz:51019/noSecurePhp/graphBuildTest.php?startJobname=PE2300DY+即在第一个'&‘处截断。
下面是构建mailto元素的代码(NL只是“
\n"):
function createBugbutton() {
$invokingUrl = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$invokingUrl = str_replace(["&", "#", " "], ["&", "%23", "%20"], $invokingUrl);
$emailBody = "Problem with graph ".$invokingUrl.NL.NL."Issue description :";
$emailLink = '<a href="mailto:some.one@some.where.com
?Subject=CA-7%20graphing%20tool%20error report
&body='.$emailBody.'"
target="_blank" class="btn btn-danger"
>Send Bug report</a>';
echo $emailLink;
}我已经将生成的HTML复制到一个空白的HTML文件中,并且行为完全相同,所以我不认为这是PHP的事情。
我做错了什么?
编辑:在评论和回答之后,我生成的HTML现在是:
<a href="mailto:some.one@some.where.com
?Subject=error report
&body=Problem with graph http://mcz/graphBuildTest.php?startJobname=PE2300DY&26;endJobnames=fred<br>
Issue description :" target="_blank" class="btn btn-danger"
>Send Bug report</a>但即便如此,它还是被转换成一个.html文件来构建电子邮件,邮件正文在“PE2300DY”之后再次停止。
新编辑:
按照公认的答案工作--谢谢大家。
发布于 2020-05-07 21:44:56
用%26替换&
我测试了一下,它是有效的:
<a href="mailto:some.one@some.where.com
?Subject=CA-7%20graphing%20tool%20error report
&body=Problem with graph http://mcz:51019/noSecurePhp/graphBuildTest.php?startJobname=PE2300DY%26endJobnames=%26jobMask=%26collapseJobnames=%26searchDepth=1%26schedId=001%26custSchedule=%26cpColour=%23ffff00%26cpStartEndColour=%23ff0000%26grpBySuite=on%26maxNodes=500%26ranksep=0.5%26nodesep=0.25%26layout=dot%26splines=spline%26rankDir=TB%26graphStyle=Full%26bgColour=%23a8a8a8%26nodeColour=%23ffc68c%26fontColour=%23000000%26nodeStyle=filled%26penWidth=3%20Issue description :" target="_blank" class="btn btn-danger">Send Bug report</a>你的函数应该是:
function createBugbutton() {
$invokingUrl = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$invokingUrl = str_replace(["&", "#", " "], ["%26", "%23", "%20"], $invokingUrl);
$emailBody = "Problem with graph ".$invokingUrl.NL.NL."Issue description :";
$emailLink = '<a href="mailto:some.one@some.where.com
?Subject=CA-7%20graphing%20tool%20error report
&body='.$emailBody.'"
target="_blank" class="btn btn-danger"
>Send Bug report</a>';
echo $emailLink;
}https://stackoverflow.com/questions/61659185
复制相似问题