AJAXリクエストを使用して、Webアプリケーションでメールジェットを使用しようとしています(送信された電子メールが「キューに入れられた」ままになり、ボックスに到達しないため、マンドリルテストが成功しなかったため):
$.ajax({
// The 'type' property sets the HTTP method.
// A value of 'PUT' or 'DELETE' will trigger a preflight request.
type: 'POST',
// The URL to make the request to.
url: 'https://api.mailjet.com/v3/send/message',
contentType: 'text/plain',
data: {
'user': '10ca83...public key 1ccd945:f58e84f9d...private key..8e9502fd7a',
'from': emaildata.email,
'to': 'recipiant@gmail.com',
'subject': 'mailjet test',
'text': emaildata.msg
},
xhrFields: {
withCredentials: false
},
headers: {
},
success: function() {
// Here's where you handle a successful response.
},
error: function() {
// Here's where you handle an error response.
// Note that if the error was due to a CORS issue,
// this function will still fire, but there won't be any additional
// information about the error.
}
}).done(function(response) {
console.log(response); // if you're into that sorta thing
});
}
ブラウザのコンソールでこのエラーが発生したため:
index.php:1 XMLHttpRequest cannot load https://api.mailjet.com/v3/send/message. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access. The response had HTTP status code 401.
私はそれを取り除くための解決策を見つけようとしましたが、2つの解決策を見つけました.1 / CORSを使用しています。2/ また、ローカル Web ページからリクエストを送信すると問題が発生する可能性があることもわかったので、wamp サーバーを実行し、代わりにブラウザーで直接アプリを起動しました。
しかし、私はまだそのエラーがあります:/何か提案はありますか? 次に、Google Gmail API を使用してメールを送信してみます。