AngularJS mailto不发送电子邮件 [英] AngularJS mailto not sending emails
问题描述
我正在使用以下代码允许我的AngularJS应用程序用户使用他们喜欢的邮件客户端发送电子邮件,但是当我单击发送"按钮时,没有任何反应.有人可以检查我的代码并告诉我我在这里到底失踪了什么吗?谢谢
I am using the following code to allow my AngularJS app users to send emails using their favorite mail client, but when I click on the Send button nothing happens. Can someone please check my code and tell me what exactly I am missing here? Thanks
<button type="button" ng-click="sendEmail(message.Email, message.subject, message.body)" >Send</button>
控制器代码:
$scope.sendEmail = function(email, subject, body){
var link = "mailto:"+ email
+ "&subject=New email " + escape(subject);
+ "&body=" + escape(body);
window.location.href = link;
};
推荐答案
我认为这里有两件事可能是错误的.
2 things I can think may be wrong here.
首先,空格不是主题中的有效字符.您可能需要用%20
替换它.
First off, Spaces aren't valid characters in the subject. You may have to replace this with a %20
.
第二,您需要先将&
更改为?
.否则,它将尝试向包含所有主题和正文参数的地址发送电子邮件...
Second, you will need to change the &
before the subject to a ?
. Otherwise it will try to send an email to the address including all of the subject and body parameters...
您可以尝试以下方法吗?
Can you try this instead:
$scope.sendEmail = function(email, subject, body) {
var link = "mailto:"+ email
+ "?subject=New%20email " + escape(subject)
+ "&body=" + escape(body);
window.location.href = link;
};
您可以在此处查看更多信息: http://en.wikipedia.org/wiki/Mailto
You can view some more info here: http://en.wikipedia.org/wiki/Mailto
这篇关于AngularJS mailto不发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!