我想通過JavaScript
想出一種方式發送電子郵件,經過一番搜索後,我發現這tutorial exampling如何使用Mandrill
做到這一點。 因此,我繼續嘗試API,到目前爲止我還沒有取得成功。使用JavaScript發送電子郵件
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript">
function validateMyForm()
{
$.ajax({
type: 'POST',
url: 'https://mandrillapp.com/api/1.0/messages/send.json',
data: {
‘key’: ‘MY KEY’,
‘message’: {
‘from_email’: ‘[email protected]’,
‘to’: [
{
‘email’: ‘[email protected]’,
‘name’: ‘MYSELF’,
‘type’: ‘to’
}
],
‘autotext’: ‘true’,
‘subject’: ‘Hello World’,
‘html’: ‘YOUR EMAIL CONTENT HERE! YOU CAN USE HTML!’
}
}
}).done(function(response) {
console.log(response); // if you're into that sorta thing
});
}
</script>
</head>
<body>
<form method="post" onsubmit="return validateMyForm();">
Email: <input name="email" type="text" /><br />
Subject: <input name="subject" type="text" /><br />
Message:<br />
<textarea name="comment" rows="15" cols="40"></textarea><br />
<input id="sendmail" type="submit" value="Submit"/>
</form>
</body>
</html>
而且,我看到firebug
報告我下面的錯誤:
SyntaxError: missing : after property id
‘key’: ‘MY_KEY€™,
當我看網頁,我看到:
function validateMyForm()
{
$.ajax({
type: 'POST',
url: 'https://mandrillapp.com/api/1.0/messages/send.json',
data: {
‘key’: ‘MY_KEY€™,
‘message’: {
‘from_email’: ‘[email protected]€™,
‘to’: [
{
‘email’: ‘SOMEONE'S EMAIL’,
‘name’: ‘MY NAME’,
‘type’: ‘to’
}
],
‘autotext’: ‘true’,
‘subject’: ‘Hello World’,
‘html’: ‘YOUR EMAIL CONTENT HERE! YOU CAN USE HTML!’
}
}
}).done(function(response) {
console.log(response); // if you're into that sorta thing
});
}
我不知道爲什麼Firefox
做那......所以我在這個問題中有兩個問題:
- 爲什麼Firefox會返回那些奇怪的符號?
- 如何讓
validateMyForm()
函數向我發送電子郵件?
我會考慮編碼問題。 –