我正在尝试使用Mandrill使用AngularJS控制器发送电子邮件。
HTML
<body ng-app="emailApp">
<section ng-controller="ContactCtrl as contact">
<form name="contactForm" id="contactForm" ng-submit="contactForm.$valid && sendTheMail()" novalidate>
Name: <input type="text" id="userName" required><br>
Email: <input type="email" id="userEmail" required><br>
Subject: <input type="text" id="userSubject" required><br>
Message: <textarea type="text" id="userMessage" required>
</textarea><br>
<input type="submit" value="Submit" id="SubmitBtn">
</form>
</section>
</body>
AngularJS
angular.module('emailApp', []);
angular.module('emailApp').controller('ContactCtrl', ['$scope', function($scope) {
$scope.sendTheMail = function() {
// create a new instance of the Mandrill class with your API key
var m = new mandrill.Mandrill('my_api_key');
// Collect Inputs
var email = document.getElementById('userEmail').value;
var name = document.getElementById('userName').value;
var subject = document.getElementById('userSubject').value;
var message = document.getElementById('userMessage').value;
var emailBody = "From: " + name + "<br><br>" + + "Subject: " + subject + "<br><br>" + message;
var params = {
"message": {
"from_email":email,
"to":[{"email":"myemail@hotmail.com"}],
"subject": "New email from website",
"html": emailBody
}
};
m.messages.send(params);
};
}]);
我没有从控制台收到任何错误,但我知道电子邮件没有发送。
编辑: 我不知道为什么早些时候没有发送电子邮件,必须与我的免费Mandrill密钥有关。这对我来说很有用。
感谢阅读。