0

Everything seems to work fine except when i try to populate to box...

my code:

Email: <input type="text" id="myTex">

<textarea id="myText">
   lorsem ipsum
</textarea>
<button onclick="sendMail(); return false">Send</button>

<script>
function sendMail() {
    var link = "&mailto=" + escape(document.getElementById('myTex').value)
             + "?cc=myCCaddress@example.com"
             + "&subject=" + escape("Welcome New agent! ")
             + "&body=" + escape(document.getElementById('myText').value)
    ;

    window.location.href = link;
}</script>

I have a problem with my Email input, it's breaking everything.. perhaps my syntax is wrong? I've tried a few different things but to no avail.. Hopefully it's something simple and i just need another set of eyes. As usual.. any help would be greatly appreciated. thank you.

cooking good
  • 1,416
  • 1
  • 14
  • 17
  • possible duplicate of [Sending emails with Javascript](http://stackoverflow.com/questions/271171/sending-emails-with-javascript) – Joe W Mar 06 '14 at 16:48
  • That's actually where i got the code from and I've left a new comment over there but no one has responded. Thanks Joe. =] – cooking good Mar 06 '14 at 16:49

1 Answers1

1

I think you want to change

var link = "&to="

to

var link = "mailto:"
David
  • 34,223
  • 3
  • 62
  • 80
  • `var link = "mailto:" + escape(document.getElementById('myTex').value)` is not working either.. – cooking good Mar 06 '14 at 16:41
  • To debug this, ignore the javascript and just make the url yourself. You should be able to put a "mailto:" link manually in your browser's address bar and have it work. If it doesn't, then it is probably a problem with your mail client. – David Mar 06 '14 at 17:09
  • In your browser's address bar, type "mailto:a@a.com" and press enter. If that doesn't work, the problem is with your mail client, not your javascript. – David Mar 06 '14 at 18:29
  • Sorry, maybe i'm not following you.. outlook opens for me fine and populates all the fields accordingly except the `to` field. – cooking good Mar 06 '14 at 18:37
  • So if you go to "mailto:a@a.com", you see a new email window in Outlook, but there isn't anything in the "To" field? If that's correct, then try it on another computer. The problem is somewhere else. – David Mar 06 '14 at 19:06