如何在PHP中构建一个mailtoHTML元素,该元素的正文中包含GET变量的URL



我正在我的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&amp;endJobnames=&amp;jobMask=&amp;collapseJobnames=&amp;searchDepth=1&amp;schedId=001&amp;custSchedule=&amp;cpColour=%23ffff00&amp;cpStartEndColour=%23ff0000&amp;grpBySuite=on&amp;maxNodes=500&amp;ranksep=0.5&amp;nodesep=0.25&amp;layout=dot&amp;splines=spline&amp;rankDir=TB&amp;graphStyle=Full&amp;bgColour=%23a8a8a8&amp;nodeColour=%23ffc68c&amp;fontColour=%23000000&amp;nodeStyle=filled&amp;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(["&", "#", " "], ["&amp;", "%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>

但即使是这个cppied到一个.html文件文件中来构建电子邮件,正文在"PE2300DY"之后再次停止

新编辑:

按照公认的答案工作-谢谢大家。

%26替换&amp;

我测试了这个,它有效:

<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;
}

相关内容

最新更新