0

I have created a simple HTML/CSS website. I also placed a small form on one of the pages. There is one editbox there for the user to write his or her e-mail address, then a Submit button to send a pre-specified e-mail to the user's e-mail address.

How can I make the e-mail get sent?

I don’t really want to use PHP as I created this site as a favour for sy and her teacher will definitely not believe she knows PHP.

Thanks.

Paul D. Waite
  • 96,640
  • 56
  • 199
  • 270
erdomester
  • 11,789
  • 32
  • 132
  • 234
  • You can't do that without using some kind of a server language. – JohnP Apr 23 '11 at 10:43
  • 3
    @JohnP not entirely correct: You *can* specify a `mailto:` link as the form's target. If the user has an E-Mail client set up, it can be sent through that. It's usually far from optimal but might be sufficient in this case – Pekka Apr 23 '11 at 10:46
  • possible duplicate of [How to send mail with a Subject using a Mailto URL?](http://stackoverflow.com/questions/1093925/how-to-send-mail-with-a-subject-using-a-mailto-url) – Pekka Apr 23 '11 at 10:49
  • @Pekka, I meant through the forms. The specific use case is not possible, but what you suggest is definitely a viable alternative – JohnP Apr 23 '11 at 10:57
  • possible duplicate of [Send e-mail from a form (only HTML, javascript)](http://stackoverflow.com/questions/2376370/send-e-mail-from-a-form-only-html-javascript) – Paul D. Waite Apr 23 '11 at 10:59

3 Answers3

0

Simple Answer: No. You do need a server-side language in order to be able to send e-mails.

However, you could create a form that is submitted to an email address. It is sent by the client and therefore an installed email application is required. Besides, the homepage visitor also needs to click the Send button.

<form action="mailto:name@domain.com" method="post" enctype="text/plain">
Email: <input type="text" name="email" />
<input type="submit" value="Submit" />
</form>

Include further text boxes between the formular tags if you'd like to send more information. Please note that the values may be modified by the client.

Fabianius
  • 695
  • 6
  • 13
  • This doesn’t quite fulfil the requirements in the question, as the OP wants to send a pre-prepared e-mail to an address specified by the end user. – Paul D. Waite Apr 23 '11 at 11:01
0

Given that you want the website to send e-mails, it’s not a simple HTML/CSS website. Sending e-mails isn’t simple.

I’m afraid you can’t use HTML or JavaScript to send a pre-prepared e-mail to an address specified by the end user. What you can do is set up a script on the server (PHP, or whatever you like) that accepts the input from your HTML form, and sends the e-mail. The person who you’re making this website for wouldn’t have to know PHP, they’d just have to make sure they don’t point the form away from the PHP script’s URL.

Paul D. Waite
  • 96,640
  • 56
  • 199
  • 270
0

Thank you for the answers. After looking through several posts on the internet i found a simple way to do this, and yes, i did it with php after all. I know, there is now e-mail verification and error message but this is enough for the one i made the website for.

    <form method="post" action="index.php"> 
    Email: <input name="email" type="text"><br> 
    <input type="submit" value="Send">
    </form> 

<?php 
$to = $_POST['email'] ; ; 
$subject = "Newsletter"; 
$email = $_REQUEST['email'] ; 
$message = "Dear XY! You subscribed to our newsletter!" ; 
$nev = $_REQUEST['name'] ; ; 
$headers = "From: $name"; 
$sent = mail($to, $subject, $message, $headers) ; 
if($sent) {echo "<script>alert('Mail sent')</script>"; } 
?> 
erdomester
  • 11,789
  • 32
  • 132
  • 234