简体   繁体   English

发送包含JQuery脚本的html电子邮件

[英]Sending html email having JQuery scripts

I'm using PHP to send html emails. 我正在使用PHP发送HTML电子邮件。 I've tried to import css files inside the email, and it works fine. 我试图在电子邮件中导入css文件,它工作正常。

<link href="http://www.mywebsite.com/css/mail_styles.css" 
      type="text/css" rel="stylesheet" />

But i want the email to look stylish with some JQuery tricks, so i tried to import the JQuery library inside the email to add some scripts, but even gmail couldn't read the library. 但我希望这封电子邮件看起来很时尚,有些JQuery技巧,所以我试图在电子邮件中导入JQuery库来添加一些脚本,但即使是gmail也无法读取库。

<script type="text/javascript" 
        src="http://www.mywebsite.com/scripts/jquery.js"></script>

So is there a way to import JavaScript libraries inside html emails ? 那么有没有办法在html电子邮件中导入JavaScript库?

Thanks ... 谢谢 ...

Most email clients either disable email JavaScript entirely, or only allow a subset of it, due to security reasons. 由于安全原因,大多数电子邮件客户端要么完全禁用电子邮件JavaScript,要么仅允许其子集。 Web-based clients such as Gmail are likely to fall into the former category. Gmail等基于网络的客户可能属于前一类。

You can try embedding the script file itself directly into the email, but overall using JS in emails is a bad idea that's best avoided. 您可以尝试将脚本文件本身直接嵌入到电子邮件中,但在电子邮件中使用JS总体上是最好避免的坏主意。

edit 编辑

Remember, email is a static content-delivery mechanism. 请记住,电子邮件是一种静态内容交付机制。 As another commentator noted, if you want to send someone dynamic content, email them a link to your DHTML webpage. 正如另一位评论员指出的那样,如果您想向某人发送动态内容,请通过电子邮件向他们发送指向您的DHTML网页的链接。

@Karim79, I'm not convinced that the answer is so clear cut as you suggest. @ Karim79,我不相信你的答案是如此清晰。

It all depends on the environment used to read the email, and whether that environemnt supports javascript or not. 这一切都取决于用于阅读电子邮件的环境,以及environemnt是否支持javascript。 Admittedly, I suspect that most email readers would be averse to supporting javascript, in order to avoid viruses and malware, but there is no absolute reason why this couldn't be done. 不可否认,我怀疑大多数电子邮件阅读器都不愿意支持javascript,以避免病毒和恶意软件,但没有绝对的理由说明为什么不能这样做。

Having said that, the unpredictable level of support offered by readers would probably mean that you shouldn't rely on the script running correctly (if at all), so you'd probably want to take a 'graceful degradation' approach. 话虽如此,读者提供的不可预测的支持水平可能意味着你不应该依赖正确运行的脚本(如果有的话),所以你可能想采取'优雅降级'的方法。

Using Javascript in emails would be a security problem. 在电子邮件中使用Javascript将是一个安全问题。 And something not desirable. 而且不可取的东西。 If you want send some fancy page to the user, why not send him the link to a page? 如果您想向用户发送一些精美的页面,为什么不向他发送链接到页面?

If I recall you can only use in-line. 如果我记得你只能在线使用。

BUT most email clients (especially web based) will genearlly not allow JS of any sorts. 但是大多数电子邮件客户端(特别是基于Web的)通常不允许任何类型的JS。

I have been advising and creating html newlstters etc for people for years now and general rule - don't use JS. 多年来我一直在为人们提供建议和创建html newlstters等一般规则 - 不要使用JS。

A good guide for html emails is: http://www.anandgraves.com/html-email-guide#javascript HTML电子邮件的一个很好的指南是: http//www.anandgraves.com/html-email-guide#javascript

我永远不会考虑在电子邮件中使用JavaScript,很可能大多数用户的电子邮件客户端都不支持它,因此不值得这样做,或者过度热心的电子邮件过滤器可能会拒绝您的邮件。

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

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