: What is required to get input from an HTML form emailed to you? I am new to HTML and trying to build a form which basically gets the data from user as an input and by clicking on send
I am new to HTML and trying to build a form which basically gets the data from user as an input and by clicking on send it should send the details to admin via email + it should also notify user on dashboard that email is sent.
I have a page with an HTML form:
<form class="well form-horizontal" action=" " method="post" id="contact_form">
I tried setting the action to my email address but that didn't work:
<FORM METHOD=POST ACTION="mailto:testemail@gmail.com" ENCTYPE="text/plain">
What is required to get the contents of the form emailed to me?
More posts by @Sarah324
2 Comments
Sorted by latest first Latest Oldest Best
HTML itself doesn't have this capability. I'm going to show a perl example and it's only one of a few ways you can send ( If you're new to HTML, probably best to focus on the PHP example you'll see someone post ). The FORM tag above where you are specifying the METHOD, needs to have its action set to a server resident script that will take your form's values and do something with them. Here's an example..
<FORM method="POST" action="/cgi-bin/mail.pl">
<INPUT type="text" name="testemail@gmail.com">
<INPUT type="submit">
</FORM>
The script (mail.pl) that action refers to above is this....
#!/usr/bin/perl -w
use strict;
use CGI;
use Email::Valid;
my $query = new CGI;
# it is important to check the validity of the email address
# supplied by the user both to catch genuine (mis-)typing errors
# but also to avoid exploitation by malicious users who could
# pass arbitrary strings to sendmail through the "send_to"
# CGI parameter - including whole email messages
unless (Email::Valid->address($query->param('send_to'))) {
print $query->header;
print "You supplied an invalid email address.";
exit;
}
my $sendmail = "/usr/sbin/sendmail -t";
my $reply_to = "Reply-to: foo@bar.orgn";
my $subject = "Subject: Confirmation of your submissionn";
my $content = "Thanks for your submission.";
my $to = $query->param('send_to')."n";
unless ($to) {
print $query->header;
print "Please fill in your email and try again";
}
open (FILE, ">>$file") or die "Cannot open $file: $!";
print $to,"n";
close(FILE);
my $send_to = "To: ".$query->param('send_to');
open(SENDMAIL, "|$sendmail") or die "Cannot open $sendmail: $!";
print SENDMAIL $reply_to;
print SENDMAIL $subject;
print SENDMAIL $send_to;
print SENDMAIL "Content-type: text/plainnn";
print SENDMAIL $content;
close(SENDMAIL);
print $query->header;
print "Confirmation of your submission will be emailed to you.";
Again, this is only one way of doing it.
Unfortunately, the solution would be more complex than simply using HTML. The pure HTML approach only allows the client browser to know that you want it to open their email client with certain information to place into the body. All of that would be done entirely on the client side with no information logged by the server, except for whatever is logged when and if the user sends the email.
Most websites would instead rely on PHP to do the work as it is more powerful and it gives you control over the information that is sent and logged. Also, it doesn't just allow for anybody to send you a random email to your address.
Unfortunately, the details about how to work with PHP may be beyond the scope of this page, but the short answer is that you would make a PHP script that would collect the data from the $_POST variable, and then use that information to send the email to you and then also to update an internal variable to note the email that was sent. All of that would be part of your website's coding.
However, there are often shortcuts, and I found a very helpful answer on a similar question on Stack Overflow:
stackoverflow.com/questions/7449767/how-do-i-send-an-html-form-in-an-email-not-just-mailto
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.