简体   繁体   English

如何将Javascript代码作为mailto href的正文发送

[英]how to send javascript code as body of mailto href

I want to do something like this. 我想做这样的事情。

I have an analytics code in JS and I want to provide that code as body of an email by email button in href="mailto:?body=code&subject=code" 我在JS中有一个分析代码,我想通过href="mailto:?body=code&subject=code"电子邮件”按钮将该代码作为电子邮件正文提供。

//Code
$code = "<script type='text/javascript'>
                    // Define the site's unique id
                    var _siteId = 'xxx-id-xxx' || null;

                    (function()
                    {
                        // create a new script element with web-seal source
                        var script   = document.createElement('script');
                        script.type = 'text/javascript';
                        script.src   = '//s3.amazonaws.com/web-seal-dont-touch/webseal.js';
                        script.async = true;

                        // insert the script element into the document
                        var firstScript = document.getElementsByTagName('script')[0];
                        firstScript.parentNode.insertBefore(script, firstScript)
                    })();
                </script>";

I want to send this part as body so I have used this function to convert this text. 我想将此部分作为正文发送,所以我使用了此功能来转换此文本。

$email_body = urlencode(htmlentities($code));


<a href="mailto:?body=<?php echo $email_body; ?>&subject=Code">Send to Developer</a>

So I am getting something like this in Body of Email Client 所以我在电子邮件客户端的正文中得到了类似的东西

&lt; , &gt; &gt;

I know, I have converted the text but that is because of it was not accepting as href mailto body properly. 我知道,我已经转换了文本,但这是因为它没有正确地接受为href mailto正文。

I want to deliver perfect text as body of mail. 我想提供完美的文本作为邮件正文。

How do I do that? 我怎么做?

All email services "scans" the content of the emails in search of malicious code. 所有电子邮件服务都会“扫描”电子邮件的内容,以查找恶意代码。 As far as I know it's not going to work. 据我所知这是行不通的。 Some email services also check links in email content for the same reason. 出于相同的原因,某些电子邮件服务还会检查电子邮件内容中的链接。

The result you see is because the email service escape characters (something like http://php.net/manual/es/function.htmlentities.php ) 您看到的结果是因为电子邮件服务转义了字符(类似http://php.net/manual/es/function.htmlentities.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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