如何用jquery,Parse,mailgun单击按钮发送邮件?
问题描述:
我想要一个邮件发送给用户,当一个网页上点击一个按钮。有没有办法使用jQuery,Parse,mailgun来实现这一点?从Parse控制台我可以使用curl调用Parse.Cloud函数。但是如何在$(“#myButton”)中点击按钮时调用“sendMail”函数。click()?如何用jquery,Parse,mailgun单击按钮发送邮件?
答
我已经这样做了,这里是我做的。
http://www.chilifunfactory.com/chili-blog/send-emails-with-parse-and-mailgun
你需要写一些解析代码云。
Parse.Cloud.define("sendMail", function(request, response) {
var mailgun = require('mailgun');
mailgun.initialize('your domain.mailgun.org', 'key-your-key');
mailgun.sendEmail({
to: request.params.toEmail,
from: request.params.fromEmail,
subject: request.params.subject,
text: request.params.comments
},
{
success: function(httpResponse) {
console.log(httpResponse);
response.success("Email sent!");
},
error: function(httpResponse) {
console.error(httpResponse);
response.error("Uh oh, something went wrong");
}
});
});
然后,在JavaScript,你可以简单地调用方法和发送电子邮件
Parse.Cloud.run('sendMail',
{
"toEmail": "customer service email address",
"fromEmail": "customer email address,
"subject": "Subject",
"comments": "Customer Comments"
},
{
success: function(result) {
alert(result);
},
error: function(error) {
alert(error.message);
}
}
);
进行AJAX发送到服务器。捕获服务器上的数据,打开卷曲,发送数据。 – Ohgodwhy 2013-04-30 01:18:16
我对服务器端编程不甚了解。如果你能指给我一个很棒的例子。 – naive 2013-04-30 01:38:02