电子邮件未使用Javascript SMTP发送

问题描述 投票:-1回答:1

我在使用Javascript SMTP发送电子邮件时遇到问题。我最初在PHP中尝试过,但是没有用,所以我选择了JavaScript,我已经看了一个星期了。我的HTML代码:

<head>
<link rel="stylesheet" href="style.css">
<script src="app.js"></script>
<script src="https://smtpjs.com/v3/smtp.js"></script>
</head>
<body>
<div class="container">  
  <form id="contact" method="post">
    <h3>Checkout</h3>
    <h4>Get your reply with in 24 hours!</h4>
    <fieldset>
      <input placeholder="Full Name" type="text" name="name" id="name" tabindex="1" required autofocus>
    </fieldset>
    <fieldset>
      <input placeholder="Email Address" type="email" name="email" id="email" tabindex="2" required>
    </fieldset>
    <fieldset>
      <input placeholder="Phone Number" type="text" name="subject" id="subject" tabindex="3" required>
    </fieldset>

    <fieldset>
      <textarea placeholder="Type your Address Here...." name="message" id="message" tabindex="5" required></textarea>
    </fieldset>
    <fieldset>
      <button name="submit" type="submit" id="contact-submit" data-submit="...Sending" onclick="sendemail(this.form)">Submit</button>
    </fieldset>
  </form> 
</div>
</body>

我的JAVASCRIPT代码:

function sendemail(form) {
    var name = document.getElementById("name").value;
    var email = document.getElementById("email").value;
    var subject = document.getElementById("subject").value;
    var address = document.getElementById("message").value;

    Email.send({
    Host: "smtp.gmail.com",
    Username : "[email protected]",
    Password : "xxxxxxx", // My Password
    To : '[email protected]',
    From : "Sender Email " + email,
    Subject : "Phone Number " + subject,
    Body : "Address " + address,
    }).then(
        message => alert("Order has been placed successfully")
    );
}
javascript
1个回答
0
投票

将此代码用作SMTP.js:

/ * SmtpJS.com-v3.3.2 * /var Email = {send:function(a){return new Promise(function(n,e){a.nocache = Math.floor(1e6 * Math.random()+ 1),a.Action =“ Send”; var t = JSON.stringify(a); Email.ajaxPost(“ https://smtpjs.com/v3/smtpjs.aspx?”,t,函数(e){n(e)})})}),ajaxPost:函数(e,n,t){var a = Email.createCORSRequest(“ POST”,e); a.setRequestHeader(“ Content-type”,“ application / x-www-form-urlencoded”),a.onload = function(){var e = a.responseText; null!= t && t(e)},a.send(n)},ajax:function(e,n){var t = Email.createCORSRequest(“ GET”,e); t.onload = function(){var e = t.responseText; null!= n && n(e)},t.send()},createCORSRequest:function(e,n){var t = new XMLHttpRequest;在t中返回“ withCredentials”? t.open(e,n,!0):“未定义”!= XDomainRequest的类型? (t =新的XDomainRequest).open(e,n):t = null,t}};

© www.soinside.com 2019 - 2024. All rights reserved.