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?

10
  • 1
    You could always implement PHP in JavaScript! Commented Feb 27, 2012 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 Commented Feb 27, 2012 at 13:26
  • No, there is no simple way to achieve this... Commented Feb 27, 2012 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. Commented Feb 27, 2012 at 13:27
  • @CharlieSomerville can you explain or point me to some resources for implementing PHP in Javascript? Commented Feb 27, 2012 at 13:28

4 Answers 4

3

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.

Sign up to request clarification or add additional context in comments.

Comments

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

Comments

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.

Comments

-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: "[email protected]",
    subject: "Some Subject",
    body: "Hello Dude!"
  },
  success: function(){
     // ...
  }
});

2 Comments

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".
Having a publicly accessible AJAX endpoint to send email is just asking for trouble, though.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.