Simple way to send e-mail using javascript - javascript

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.

Related

Validate Form with PHP with Data Posting to Java Application

I have a Java application (servlet, written by someone else) that does some processing. I have a PHP application (web site HTML that uses PHP in places) on top that posts data to the Java application:
<form method="post" action="http://site/java" onsubmit="return validate(this)">
I have the JavaScript validating, as well onsubmit.
This works fine, but when I try and validate with PHP (in case JS is disabled), I run into problems.
I'm not sure how to do this. I've tried a few things but none has been really what I want. I want to be able to mimic the JS behavior but with PHP.
It would be cool if I could do something like this:
if ('POST' == $_SERVER['REQUEST_METHOD']) {
//do post to servlet
}
I've tried other things like this:
if (isset($_POST['field'])) {
//validate form with function
}
Part of the problem is that the Java application also does some validation and returns some parameters I can get. I might use something like this to check these:
if ($_GET['error'] == 'invalidEmail') {
$error = 'Please enter a valid email address.';
}
How would I do this? Can I use Location response header or does this not send POST data? If I set action="" and post back to page, I can get the PHP to validate but obviously the whole point is to post to the Java application.
You can use REST to post to your java application from php. More specifically the cURL library.

how to fetch post() method parameter through javascript?

i'm working on mobile development and developing pure JavaScript, CSS and HTML code, cant use any server side scripting like PHP, Jsp n all since i have to feed it in phone-gap. I just want to know how i can fetch the post parameters through JavaScript(like in jsp we fetch it through request.getparameter) ? please help me out guys thanks in advance.
There is no way to read POST data from the request that generated the current page using client side JavaScript.
In my mind you have the change the way your app will work. But if you really want to send your form on a page, you can use GET method and retreive parameters from the URL
http://css-tricks.com/snippets/jquery/get-query-params-object/
The normal way : on form submit you should have a JS function, and this function has to do the job.
Do not forget to use Google/Stackoverflow.com you should find your answer ;-)
How do you post a form in Phonegap?

How to fill another website's form with the data in my own website

Here is the thing, I have a form in my web site looks like something like this:
Name: ----
Last name: ----
.
.
.
something like this, I work with a site that I have to send this information and type this requests again in that site with the same fields.
It means I want to copy my forms data to the target website's form with the same fields.
I do not have the access to target website's codes and I'm just a user there.
So I want to know if there is a way using Jquery, javascript or anything help me make a button that When I click that the data copy from my site to the target website.
Is it possible to access another browser's page tab inside another one??!! with jqyery?
Thank you in advance
I haven't tried your problem, and this is just an opinion.
If that website is using a get() method, you are saved. You can form a query string in the same format and execute it, else if you are trying to do something like that automatically if there is some captcha check you may fail, and the server will be blocking you thinking it's a DOS attack.
And this is something which may be helpful to you.
Javascript communication between browser tabs/windows
var w2 = window.open("Website you need to fill the form");
Now use w2 as owner window, in order to access the elements.

Sending mail from javascript

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

What's the best way to submit a form to a form script on another site?

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>

Categories