我正在尝试通过带有SendGrid + Parse云代码模块的表单发送电子邮件。一切都在功能上很好,电子邮件正在通过。但是,当我查看我的日志时,我得到以下内容:
Result: ReferenceError: response is not defined
// main.js
var express = require('express');
var sendgrid = require('sendgrid');
sendgrid.initialize("USER", "PASS");
var app = express();
// App configuration section
app.use(express.bodyParser()); // Middleware for reading request body
app.post('/email', function(req, res) {
var name = req.body.name;
var email = req.body.email;
var message = req.body.message;
sendgrid.sendEmail({
to: 'email@gmail.com',
from: email,
subject: 'Message from ' + name + ' via Web',
text: message
}, {
success: function(httpResponse) {
console.log(httpResponse);
response.success("Email sent!");
},
error: function(httpResponse) {
console.error(httpResponse);
response.error("Uh oh, something went wrong");
}
});
});
答案 0 :(得分:0)
response
未定义,我认为你打算写
sendgrid.sendEmail({
to: 'email@gmail.com',
from: email,
subject: 'Message from ' + name + ' via Web',
text: message
}, {
success: function(httpResponse) {
console.log(httpResponse);
httpResponse.success("Email sent!");
},
error: function(httpResponse) {
console.error(httpResponse);
httpResponse.error("Uh oh, something went wrong");
}
});
BTW:你应该始终通过"使用严格的"来设置严格的模式。 - 这会更快地捕获未定义的变量。