Can anybody tell me how to send mail with an attachment using JavaScript?
You have two options to send email:
Open the local email client from JavaScript and user can send email with pre-populated data.
var link = "mailto:[email protected]";
// In addition to this you can add subject or body as parameter .
// For e.g.
// "mailto:[email protected]?subject=test subject&body=my text"
window.location.href = link;
JavaScript is a client-side language. It is not concerned with (indeed, cannot) send e-mail, with or without an attachment. You'll need something server-side for that.
JavaScript can merely invoke the server-side script to send the e-mail, by requesting it, say, over AJAX, but it is not JavaScript which sends the e-mail.
This is akin to people mistakenly writing things like "I have some JavaScript which is getting some info from my database." It is not - it is requesting a server-side script which is getting the info from the database.
With pure JavaScript, you can't send e-mails from the client. Remember, JavaScript is executed at the client (i. e. the user's browser).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With