使用JavaScript发送电子邮件

cyb*_*ron -1 html javascript forms

我正试图通过一种方式发送电子邮件JavaScript,经过一些搜索,我发现本教程将使用如何进行操作Mandrill.因此,我继续尝试API,到目前为止我还没有成功.

<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’: ‘SOMEONE@EMAIL.COM’,
                ‘to’: [
                    {
                        ‘email’: ‘MY@EMAIL.COM’,
                        ‘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>
Run Code Online (Sandbox Code Playgroud)

此外,我看到firebug报告我以下错误:

SyntaxError: missing : after property id


‘key’: ‘MY_KEY€™,
Run Code Online (Sandbox Code Playgroud)

当我查看页面时,我看到:

function validateMyForm()
{
    $.ajax({
        type: 'POST',
        url: 'https://mandrillapp.com/api/1.0/messages/send.json',
        data: {
              ‘key’: ‘MY_KEY€™,
              ‘message’: {
                ‘from_email’: ‘MY_EMAIL@EMAIL.COM€™,
                ‘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
        });
}
Run Code Online (Sandbox Code Playgroud)

我不知道为什么Firefox这样做......所以我在这个问题中提出了两个问题:

  • 为什么Firefox会返回那些奇怪的符号?
  • 如何使validateMyForm()功能向我发送电子邮件?

Joh*_*nde 5

你正在使用时髦的报价:.将它们改为单引号:'.