Search code examples
javascriptmailtowindow.open

How to Create a Mailto Share Button that Opens a Window in which Ones Can Enter Email Address to Send to


I've been searching all over the internet to find out how to create a mailto share button that opens up a new window in which the user can then type in the email address of his choice to send to. I've an attached a sequential set of images as operational example:

What is the trick to this? Why can't I find any info on how to write such code ....absolutely nowhere on Stack Overflow either!

As of right now this is the code that I have:

 $('.share-page-on-Email').click(function() {
  window.open("mailto:"+emailTo+'?cc='+emailCC+'&subject='+emailSub+'&body='+emailBody, '_self');
   });

View my prototype Email share button at my Code Pen here: https://codepen.io/IDCoder/full/rpdBQJ/

Thanks in advance for your help!


Solution

  • I recommend never using that mailto: feature as it behaves unpredictably, different on different devices and sometimes fails alltogether. You could create a page just to take the email string then do whatever you want with it server side. Make the popup/popover small like:

    <a href="/my-email-collector-page"
       onclick="window.open(this.href,'targetWindow',
                                       'toolbar=no,
                                        location=no,
                                        status=no,
                                        menubar=no,
                                        scrollbars=yes,
                                        resizable=yes,
                                        width=200px,
                                        height=120px');
     return false;">email</a>