php - 如何在 PHP 中使用带有 GET 变量的 URL 构建 mailto HTML 元素
问题描述
我正在我的 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>
但即使这个 cpied 到一个 .html 文件文件来构建电子邮件,正文在“PE2300DY”之后再次停止
新编辑:
按照公认的答案工作 - 谢谢大家。
解决方案
替换&
为%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;
}
推荐阅读
- java - 谷歌地图未在 Android Studio 中显示(只有谷歌图标可见)
- c# - 使用 AddExtension 时无法使用 firefox 驱动程序 selenium 加载扩展
- angular - 如何使用 Angular8 将焦点设置在具有动态生成的元素 ID 的材质输入上
- kubernetes - Pod 之间的亲和性和反亲和性。确保 webapp 连接到本地 redis 缓存
- html - 为什么子 div 不会超出 flex 行容器
- ios - 将 UIContainerView 嵌入到表视图中并尝试通过 @IBOutlet 访问导致 Unexpectedly found nil
- css - 根据其值显示图标(Angular 4+)?
- python - Django Wagtail:我们可以选择编辑任何 Page 模型的 list_display 吗?
- csv - 在 DataWeave 2.0 中读取不带标题的 CSV
- windows - 如何以编程方式为应用程序设置默认输入和输出音频设备?