dimanche 26 février 2017

Sending Email with a generated ID in Subject

So here is the link of the fiddle. I already tried a lots of searches and tried combining codes from other sites but cant seem to figure out the error. http://ift.tt/2lLqYMo

Based on the subject i just need pop up outlook with the ID in it. Sorry im a bit beginner here. :)

The random generator is already working i was able to test that separately. The only problem is the sending of email. If you try to click the link nothing happens, it would just load for a couple of seconds then stops.

function generateEmailID(length, chars) {
        ' Set default values
        var result = '';
  var timestamp = +new Date().toString(36).slice(2);
    
  'Set optional values
  length = length || 7;
  chars = chars || '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  
  'Generate the id based on the parameters with timestamp
  for (var i = length; i > 0; --i)
                result += chars[Math.round(Math.random() * (chars.length - 1))];
        return timestamp + result;
}

var sendEmail = document.getElementById("simpleHref");
sendEmail.href = "mailto:asdf@asdf.com?subject=Report&body=" + encodeURIComponent(window.location);


function sendEmail(email, subject, body) {
        'Set optional values
  email = email || "random@random.random"
        subject = subject + " [" + generateEmailID() + "]" || "Test [" + generateEmailID() + "]"
  body = body || "Test"
  
  'Send email with id generated in the subject
        window.location.href = "mailto:" + email + "?subject=" + subject + "&body=" + body;


}
<a href="#" onclick="sendEmail()">Send Email</a>



Aucun commentaire:

Enregistrer un commentaire