[英]How to build a mailto HTML element in PHP with URL with GET vars in body
我正在我的 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>
該按鈕看起來不錯,並且當我在它上面使用 hover 時,狀態欄中顯示的 URL 看起來還不錯,盡管“&”只是顯示為“&”,即 ZE6B391A8D2C4D45902A23A8B6D 看起來是正確的。
當我單擊該按鈕時,我得到一個新的 email 具有正確的地址和主題,但正文只是:
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 文件文件中來構建 email 身體在“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 應該是:
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;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.