+ 3

How to send a result of ( my location) to an email? ( check the code in my codes called get location)

I have a code that gets your location longitude and latitude and i want the results to be sent to an email upon pressing the button

2nd Mar 2017, 5:11 AM
Sam Sung
Sam Sung - avatar
9 odpowiedzi
+ 4
You have an unexpected case in your script: it fails silently if user have denied geolocation, or in case of 'geolocation' object is supported by user brower but another error occurs in the process of getting location :P To fix it, you need to add a call back function for handling geolocation errors, modifying the call by adding this handler as second parameter... Corrected/improved script: var x = document.getElementById("demo"); function getLocation() { console.log('test '+x); if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(showPosition,geoError); } else { x.innerHTML = "Geolocation is not supported by this browser."; } } function geoError(error) { x.innerHTML = 'ERROR('+error.code+'): '+error.message; } function showPosition(position) { x.innerHTML = "Latitude: " + position.coords.latitude + "<br>Longitude: " + position.coords.longitude; }
2nd Mar 2017, 6:20 AM
visph
visph - avatar
+ 1
<a href="mailto:rkcxyz@email.com"> submit
2nd Mar 2017, 5:37 AM
Raj Kumar Chauhan
Raj Kumar Chauhan - avatar
+ 1
There is no way to send an email from browser js directly. You will have to use AJAX to send it to the server, where it can be processed, or create a link with mailto: and prefilled content. http://stackoverflow.com/questions/4782068/can-i-set-subject-content-of-email-with-using-mailto
2nd Mar 2017, 5:42 AM
spotbot2k
spotbot2k - avatar
+ 1
this link will open email app (outlook etc) and will ask for sender, subject etc. Btw you can specify all these things in this tag itself. let me check if I can find any good link for you.
2nd Mar 2017, 5:53 AM
Raj Kumar Chauhan
Raj Kumar Chauhan - avatar
+ 1
http://stackoverflow.com/questions/4782068/can-i-set-subject-content-of-email-with-using-mailto you can specify subject, cc, bcc, content etc but I don't think you can specify sender id here. sender id you can enter when email app open. better option is to use php or any other server side language.
2nd Mar 2017, 6:01 AM
Raj Kumar Chauhan
Raj Kumar Chauhan - avatar
+ 1
haha...now I see, I have shared same link shared by alex. I can't edit comments so leaving it as it.
2nd Mar 2017, 6:02 AM
Raj Kumar Chauhan
Raj Kumar Chauhan - avatar
0
Raj, if i may ask, the email will be sent from who??
2nd Mar 2017, 5:40 AM
Sam Sung
Sam Sung - avatar
0
Alexander thanks for the answer i will look through it and will get back with more questions i suppose.. And can you recommend a place for learning AJAX??
2nd Mar 2017, 5:45 AM
Sam Sung
Sam Sung - avatar
0
Raj haha i noticed. Thanks for the answer i shall experiment and will try to get it work if i fail I'll get back to you guys! Thanks alot
2nd Mar 2017, 6:06 AM
Sam Sung
Sam Sung - avatar