0
我正在localhost(在一個靜態React網絡應用程序內)和表單提交,我想通過我的聯繫表格發送電子郵件。所以我張貼到mailgun API,像這樣:通過mailgun API發送郵件只使用客戶端AJAX請求
axios({
url: 'https://api:[email protected]/v3/somesandboxdomain1c.mailgun.org/messages',
method: 'post',
username: 'api',
password: 'key-somekey',
data: {
from: "Excited User <[email protected]>",
to: "[email protected]",
subject: "Hello from react app",
text: "Testing some Mailgun awesomness!"
},
headers: {
"Content-Type": "application/x-www-form-urlencoded",
'Authorization': `Basic ${window.btoa('api:key-someapikey')}`
}
})
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
,但我不斷收到此錯誤或它的一個變化:
XMLHttpRequest cannot load https://api.mailgun.net/v3/somesandbox.mailgun.org. Request header field Authorization is not allowed by Access-Control-Allow-Headers in preflight response.
我使用的是靜態的Web應用程序,沒有任何服務器,通過它發送數據。我已經嘗試添加和刪除各種標題,如Access-Control-Allow-Headers: Authorization
等似乎沒有任何工作
你知道了嗎?我以爲你只能從服務器發送 – timh
@timh沒有你必須使用服務器 –