I am developing a static website where in i want to send an email when HTML "Send Button" is clicked. IF it is possible it would be nice if u can share the code
Thanks
short answer: No!
Long answer:
No, you can't send emails from static pages even using javascript. What you can do is to use ajax to send email from your html form.
It is possible ;-)
<input type="submit" value="Send" onclick="window.location ='mailto:email#address.com' "/>
In short: Forget it.
If you want to send email with the slightest resemblance of reliability, use a server side process. If you want to use JavaScript then you can use Ajax to pass the data to that server side process and/or SSJS.
It is not possible to send email from Javascript, you'll need to write a page in a language like PHP to receive the POST data and use the mail() command there.
I'm sorry but just with a static website you can't do it. One imaginable possibility would be make a very complex javascript code to access one webmail account you have, login there and send the email using this account to you. It's theoretically possible, but I've never seen something like it...
Related
I'm trying to implement a third party tool. This tool uses a form with the post method to send data to their site. Is there any way that I can mimic this action without using the form tag? I don't know much about jquery post and same domain (this is sending it off to a different domain) so I don't know if there would be an issue with this.
Everything that I've found in my search talks about ajax and returning content after you post but all I want to do is to take the customer to the third party's site after they have submitted the form.
thanks!
You cannot send data to a different domain with AJAX. Its not permitted by the browser. As for can you do it without a form element, yes. Just encode the data as it would look in a browser get URL like http://site.com/search?query=I+love+js&perpage=10&page=2
datatosend="field1="+value+"&field2="+value2
$.post(url,datatosend,function(data){//do something with data. location.href="new location"}
Yes you can.
Check out this post.
https://stackoverflow.com/a/1078991
also found in the docs
http://api.jquery.com/jQuery.post/
http://api.jquery.com/jQuery.post/
and then you can do a location.replace() when it is completed
function replaceDoc()
{
window.location.replace("http://www.thatsite.com")
}
I need to submit some information to my servlet. Once I submit this information, I'll receive a PDF from the servlet based on the data. I know I can construct the URL and pass parameters to it using HTTP GET. Suppose my form data is too large.So is it possible to do this using a hidden iFrame? I'll submit the parameters using the hidden iFrame and in my servlet, I write the PDF to the response stream. Will this work? If it works can someone please suggest me how to do this?
You'll need to set the target to the iframe you want to submit it to.
<form action='...' name='theform' target='theiframe'>
.
.
.
<iframe name='theiframe' src='...'>
</iframe>
</form>
This forum post has some details : http://forums.powweb.com/showthread.php?t=77213
Hm, which way do you want to sent the data using your iframe? I think you're limited to either GET or POST there, too. Means, if your data is too large, the iframe won't help sending your data.
What server backend do you use? You might be able to configure the maximum size of request data (post / get).
Please have a look at this message for more information about this.
In my eyes, using the hidden Iframe method is very old school, almost like before the great days of Ajax methods.
You can use jquery Ajax call and serialize your full form passing all variables. Remember to check your request size in your config, in case it post reaches maximum size.
I am trying to write a function to send an email when the user clicks on "submit".
Any ideas how to do so?
Lets say I have a
<script>
function mail()
{
var players = document.getElementById('players').value;
var slots = document.getElementById('slots').value;
}
</script>
and I want to generate an mail with those three vars.
Thanks all :)!
You can't send emails from (client-side) JavaScript alone. What you can do is write a server-side program that takes inputs (maybe as a POST or XHR request), creates an email out of it and sends it.
You may need to post the details to a server which would mail or you can use the mailto function to invoke default mail client on the client's computer like
<form action="mailto:sample#stackoverflow.com" method="post" enctype="text/plain" >
variable1:<input type="text" name="v1">
variable2:<input type="text" name="v2">
<input type="submit" name="submit" value="Submit">
</form>
You will have to use it in combination of a server side language and javascript. You can use javascript to write the "interface" to the mail function. But you will need to look into php or another language.
A php example of this is
You can find more details on the manual here http://us.php.net/manual/en/book.mail.php
pinehead.tv fighting for smarter newbies
"You may need to post the details to a server which would mail or you can use the mailto function to invoke default mail client on the client's computer like
variable1:
variable2:
"
This answer above will not work for people who do not have a mail client installed on their os. the mailto feature in html will open up the users "outlook" type program to send the mail.
I am working on a basic HTML page that requires the user to send details to a script located on a third-party website. What I require is for the user to fill out a form on my web page, and have that information submitted to another third-party form.
I do not wish to return anything to the user, other than whether the submission was successful or not. I also do not want the user to have to go to this third-party site to submit using their form.
It was suggested by the website itself to use an iframe and hold its form on your page, but I was wondering what other, preferably better methods are available to me. It'd be nice if there were some form of jQuery/js code I could use to do such a thing.
It'd be nice if there were some form
of jQuery/js code I could use to do
such a thing.
One way is to use jQuery's $.ajax or $.post methods like this:
$.ajax({
url: url,
success: function(data) {
alert('succeeded');
}
});
Maybe you could try cURL with CURLOPT_POST and CURLOPT_POSTFIELDS?
well it depends if you have control over the other website as well. as in you are able to access the code.
If you are you can use JSONP to pass the values and get a response, but to do it you will have to assign a callback that is sent and then formatted at the front of a JSON object for it to work (they do this for security).
The other option is to use a php ob_start() function. (Note: this will only work if the form you are trying to submit these values to allow $_GET to be used to proccess the form)
ob_start();
include('http://wwww.anotherwebsite.com?key1=value1&key2=value2&key3=value3');
$returnString = ob_get_contents();
ob_end_clean();
So then from here $returnString is the result, which you can basically search (strpos() to see if true is how I would do it) in php to find key words to see if it was successful or not or what ever you need to check for.
But again, this only works if the form on the remote server uses $_GET and not $_POST (or allows both through globals).
I know this is a php solution, but a warning is that for security purposes, there are serious restrictions on what javascript can do cross server.. the best javascript way to do cross server is JSONP, which jQuery does support so you might want to look into that.. but as I mentioned, for it to work you need to have a callback be able to be sent back with the response, and the response needs to be in a jsonp object format.. (basically you either need to 1. have the other server have a jsonp api for you to use or you have control over the other server's server side files to make the changes needed).
Do you want like that? It's simple form submitting to another website. But, I can't check whether it's successfully submitted or not.
<form action="http://www.another.com">
<input name="myInput" type="text">
<input type="submit" value="Submit">
</form>
I wanted to know how to send e-mail using javascript.
I dont want to use long functions with tag n all other stuff. Interested in only one/two liner statement which will allow me to send mail.
I have used something like that earlier :
function sendmail(_frm)
{
var eml="you#youraddress.com";
var bod="&body="+_frm.selOne.value+" ¦¦ "+_frm.txtOne.value;
var subj="?subject=Whatever you want";
location.href="mailto:"+eml+subj+bod;
}
At Form tag
<form action="mailto:you#youraddress.com"
enctype="text/plain"
method="POST" onsubmit="sendmail(this);return false;">
I dont want to use above approach to send mail...
Please provide me your suggestion so that i can send mail very easily by using javascript , like below.
e.g.
function sendmail () {
location.href="mailto:<other stuff>"
}
Is anyone has any idea about this, please share their ideas here.
Thanks a lot....
As far as I know there is no other way to send an e-mail from client side with javascript. You can write some server side code or you can find some service to send e-mail. Unfortunaltely I dont know any web application that gives that kind of service. But, I was writing a web application that have limited e-mail functionality added. It is not finished yet (but still usable).Address is http://postdatabase.appspot.com
Like I said it is not finished yet, that's why I suggest you to find a completed product. if you decide to use it please contact me from the site, so I can be more carruful to make changes.