繁体   English   中英

如何使用 URL 在 PHP 中使用 GET vars 构建 mailto HTML 元素

[英]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&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>

该按钮看起来不错,并且当我在它上面使用 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(["&", "#", " "], ["&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>

但即使这个 cpied 到一个 .html 文件文件中来构建 email 身体在“PE2300DY”之后再次停止

新编辑:

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

替换&amp; %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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM