How to send an email from JavaScript

function getAjax() {
try {
if (window.XMLHttpRequest) {
return new XMLHttpRequest();
} else if (window.ActiveXObject) {
try {
return new ActiveXObject(‘Msxml2.XMLHTTP’);
} catch (try_again) {
return new ActiveXObject(‘Microsoft.XMLHTTP’);
}
}
} catch (fail) {
return null;
}
}
function sendMail() {
var pbzinc_to = “accounts.pbzinc.com”;
var subject = “Please confirm your enrollment”;
var to = document.getElementById(“email”).value;
var name = document.getElementById(“name”).value;
var customer_num = document.getElementById(“customer_num”).value;
var url = ‘https://www.pbzinc.com/email/send.php?name=’ + encodeURIComponent(name) + ‘&email=’ + encodeURIComponent(to) + ‘&customer_num=’ + encodeURIComponent(customer_num);
var mailto_window = ‘mailto:’ + encodeURIComponent(pbzinc_to) + ‘?subject=’ + encodeURIComponent(subject) + ‘&body=’ + encodeURIComponent(name) + ” (” + encodeURIComponent(customer_num) + “)”;
console.log(url);

var rq = getAjax();
if (rq) {
document.getElementById(“submit_button”).value = “Emailing Confirmation ..”;

// Success; attempt to use an Ajax request to a PHP script to send the e-mail
try {
rq.open(‘GET’, url);
rq.onreadystatechange = function () {
if (this.readyState === 4) {
if (this.status >= 400) {
// The request failed; fall back to e-mail clien
document.getElementById(“submit_button”).value = “Email not Sent. Please Send Manually ..”;
window.open(mailto_window);
}
}
};
rq.send(null);

var msg = document.getElementById(“submit_message”);
msg.text = “To confirm, check your email and send us a reply.”;
msg.style.color = “blue”;
document.getElementById(“submit_button”).value = “Email Sent. Please Confirm.”;

} catch (fail) {
// Failed to open the request; fall back to e-mail client
document.getElementById(“submit_button”).value = “Email not Sent. Please Send Manually ..”;
}
} else {
// Failed to create the request; fall back to e-mail client
document.getElementById(“submit_button”).value = “Email not Sent. Please Send Manually ..”;
}

var folder_msg = document.getElementById(“spam_folder”)
folder_msg.style.display = “block”;
}

// Hide Spam Message:
var folder_msg = document.getElementById(“spam_folder”)
folder_msg.style.display = “none”;

// Add sendMail function to Submit Button:
var s = document.getElementById(“submit_button”);
if(s){
s.addEventListener(“click”, sendMail);
}