Skip to content Skip to sidebar Skip to footer

How To Send Mail With Attachment Using Js?

Can anybody tell me how to send mail with an attachment using JavaScript?

Solution 1:

You have two options to send email:

  1. Use server side implementation to send email, access it in Javascript via XMLHttpRequest
  2. Open the local email client from JavaScript and user can send email with pre-populated data.

    var link = "mailto:target@example.com"; 
     // In addition to this you can add subject or body as parameter . // For e.g. // "mailto:target@example.com?subject=test subject&body=my text"window.location.href = link;
    

Solution 2:

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.

Solution 3:

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).

Solution 4:

You can't send an email directly from Javascript. You could use it to do an AJAX call to send mail from whatever server side language you are using.

If you were using PHP:

Sending email via PHP

Post a Comment for "How To Send Mail With Attachment Using Js?"