1

I have a need for a simple html + javascript page that must send multiple emails to a predefined list of users upon a button click.

I need the html page to be able to run locally on a machine that does not have a web server installed.

If it was just the html page by itself, this would be no problem. But from everything I've read, it is not possible to send emails directly from javascript/jquery (see this StackOverflow post here for example). Instead, I have to call some kind of script to actually send the emails.

I also looked at this post, but this one seems to be about running a self contained script, not invoking a method with parameters. I'm not sure that this is what I need.

I am looking for a way to send the emails without requiring that a web server be running on the machine. It doesn't have to be PHP. Is there any simple way I can do this without requiring a web server to exist on the machine?

Community
  • 1
  • 1
Amanda Kitson
  • 5,477
  • 12
  • 49
  • 73
  • 1
    You could always implement PHP in JavaScript! –  Feb 27 '12 at 13:25
  • well, you can host the php script anywhere, doesn't have to be the same host/server/machine on which you have the html page. You could also use the annoying "mailto" which basically uses the default email client – scibuff Feb 27 '12 at 13:26
  • No, there is no simple way to achieve this... – soju Feb 27 '12 at 13:27
  • 1
    Don't think you'll have any other possibility than using a `mailto:`-href if you want things to run locally. – m90 Feb 27 '12 at 13:27
  • @CharlieSomerville can you explain or point me to some resources for implementing PHP in Javascript? – Amanda Kitson Feb 27 '12 at 13:28
  • @scibuff Do you know if there are any existing php scripts that are publically accessible (such as gmail, maybe?) that allows folks to use them to send email from javascript? Or maybe a publically usable ajax interface for gmail? I expect to still have to send in a username and password to send the email... – Amanda Kitson Feb 27 '12 at 13:30
  • @AmandaMyer I think Charlie was being facetious. – Zoidberg Feb 27 '12 at 13:33
  • And I will point out the obvious here, why would you want to do this? If I am a user, I do not want my computer turned into an e-mail sending spam machine that could be exploited. i think you need to take a look at the why before you go to far on the how. – Zoidberg Feb 27 '12 at 13:34
  • @Zoidberg The "why" is because I've been asked to create a very small application that will autogenerate several reminder emails to a list of volunteers based on the days those volunteers have signed up to volunteer. They want to keep the costs as low as possible, and don't have any existing web servers. They also want to be able to run it from both PC and MAC (which is why I was thinking a web form instead of a windows app). – Amanda Kitson Feb 27 '12 at 13:55
  • @AmandaMyer why not a java application? – Zoidberg Feb 27 '12 at 13:58

4 Answers4

4

To answer your question: no, there is no way to run server-side code (which sending an email must be) without having a server to run that code - PHP, Python, Ruby or anything else.

You could look at using a third-party service like http://postageapp.com/ - but be aware that there'll be costs involved, and you'll have to route the content of those emails through that third-party service.

Adam Hepton
  • 674
  • 1
  • 6
  • 12
1

You're going to need some form of server-side script to hook up to the SMTP server.

Because JavaScript doesn't support cross-domain requests, you can't $.post() to an external URL either...

hohner
  • 11,498
  • 8
  • 49
  • 84
1

You can run PHP without the web server and use it as a command line tool:

http://www.php.net/manual/en/features.commandline.usage.php

Your problem will be that you need some way of getting the "state" of your client/server information from JavaScript over there. You can't (easily) write files with JavaScript, but you can issue standard HTTP requests. For this you would need a web server.

You say that this will run stand alone on a workstation. You may find it easier to adjust the security permissions (see here) to write to a local file containing the email parameters and then use a cron job or scheduled task on the local machine to parse the file kick off an email.

Community
  • 1
  • 1
Duane Gran
  • 490
  • 4
  • 9
-2

You need to trigger a server-side script in order to send emails.

If you have the option to use another webserver you could call the script via AJAX like this:

$.ajax({    
  url: "http://some.remote.server/send_email.php",
  data: {
    receipient: "some.guy@domain.tdl",
    subject: "Some Subject",
    body: "Hello Dude!"
  },
  success: function(){
     // ...
  }
});
Paul Voss
  • 705
  • 1
  • 6
  • 18
  • My bad, I guess I shouldn't have written "ajax". But there is a way to access remote scripts via GET requests, isn't it?. At least there is a Twitter JSON API that one can access "crossdomain". – Paul Voss Feb 27 '12 at 15:36
  • Having a publicly accessible AJAX endpoint to send email is just asking for trouble, though. – Adam Hepton Feb 28 '12 at 10:49