Create A Function To Send Mail From A Div
I've several divs with a email icon.
Solution 1:
The input to a click handler is an event object. Within that event object you can get the element that was clicked on and therefore it's id, which in your case holds the email address
$('.icon-send-mail').click(function(event) {
var mailto_link = 'mailto:'+event.target.id;
var win = window.open(mailto_link,'emailWindow');
});
Solution 2:
Edit the first line within your function:
/* You were passing the event object! */var mailto_link = 'mailto:'+this.id;
Custom JQuery vs JavaScript performance benchmark
JavaScript/JQuery
$(document).ready(function(){
$('.icon-send-mail').click(function(event) {
var mailto_link = 'mailto:'+this.id;
var win = window.open(mailto_link,'emailWindow');
});
});
Pure Javascript
window.onload = function () {
var elems = document.getElementsByClassName('icon-send-mail');
for (var i in elems) {
if (elems[i].nodeType == 1) elems[i].addEventListener('click', function (event) {
var mailto_link = 'mailto:' + this.id;
var win = window.open(mailto_link, 'emailWindow');
});
}
};
Bonus CSS
.icon-send-mail {
cursor: pointer;
}
Live Demo
Solution 3:
You're on the right track:
$( document ).ready( function() {
$('.icon-send-mail').on('click', function(e) {
var mailto_link = 'mailto:' + $(this).attr('id');
var win = window.open(mailto_link, 'emailWindow');
});
});
Solution 4:
You should replace your this line:
var mailto_link = 'mailto:'+email;
with the following line:
var mailto_link = 'mailto:'+($(this).attr('id'));
Solution 5:
Hi Call below code inside you Click event
$.ajax({
type: "POST",
url: "Mail.aspx/SendMail",
cache: false,
contentType: "application/json; charset=utf-8",
data: "{ 'body':'" + messageBody + "'," +
"'to': '" + msgTo + "'," +
"'from': '" + msgFrom + "'," +
"'subject': " + msgSubject + "'" +
"}",
dataType: "json",
complete: function (transport) { if (transport.status == 200) $("#formcontainer").html("Success"); elsealert("Please try again later"); }
});
and write the mailing code on Code behind
MailMessagemail=newMailMessage();
SmtpClientSmtpServer=newSmtpClient("smtp.gmail.com");
mail.From = newMailAddress("me@mydomain.com");
mail.To.Add("u@urdomain.com");
mail.Subject = filename;
mail.Body = "Report";
Attachmentattachment=newAttachment(filename);
mail.Attachments.Add(attachment);
SmtpServer.Port = 25;
SmtpServer.Credentials = newSystem.Net.NetworkCredential("me", "password");
SmtpServer.EnableSsl = true;
SmtpServer.Send(mail);
Post a Comment for "Create A Function To Send Mail From A Div"