I have made and html file following the books Computer Learning by Sumita Arora and it's Cornestone class 7. I have been making a form using chapter 7, and it's not working! The full code is (the wrong line is the mailto: line)
<!DOCTYPE html>
<html>
<head>
<title>A Form</title>
</head>
<p>A Form</p>
<body style="background-color:grey">
<form action = "mailto:email address blured for obvious reasons" method = "post">
<p>
<b>First name:</b>
<input type = "text" id = "firstname" style="background-color:black"><br/>
<p><b>Last name:</b>
<input type = "text" id = "firstname" style="background-color:black"><br/></p>
<p><b>School:</b>
<input type = "text" id = "School" style="background-color:black"></br></p>
<p><b>Address</b>
<input type = "text" id = "Address" style="background-color:black"></br></p>
<input type = "submit" value = "Send" style="background-color:black"> <input type = "reset" style="background-color:black">
</br>
Copyright © Manik Sharma (THEOP05) 2022
</p>
</form>
</body>
</html>
CodePudding user response:
mailto
does not send an email in an automated way. It instructs the user's browser to show the user an email client. When I run your code on my local machine, the "Submit" button pops open Mozilla Thunderbird, since that's the email client installed on my machine. If you don't have an email client installed on your machine, then it's possible nothing will happen.
Of course, that's the client's machine, which is very likely not what you want. If you really want your form to send an email with the form results to [email protected]
, you need to do that routing on the server side. The details will depend on your server framework (Django, Rails, PHP, etc.), but you should add an ordinary HTTP endpoint on your server, something like http://example.com/form-submit
, which takes the form input as a POST parameter and, using whatever language your server is written in, sends the email server-side.
I know Django has facilities for automating the handling of forms (and conventions in place to make it easier). I suspect Rails does as well.
CodePudding user response:
Try to change the method to "get"
<form action = "mailto:email address blured for obvious reasons" method = "get">
CodePudding user response:
In order to send email with a form, you need an email delevery service. In the MVC, Html is the view (frontend) and sending email should be done by the controller or the model (backend). I like to use mailgun, but any other large scale email delevry service will provide you a nice UI and multiple usefull features. If your backend is PHP, you can use composer to install dependencies. I recommand the symfony mailer composer require symfony/mailer
with you favorite 3rd Party Transport (eg.: composer require symfony/google-mailer
for gmail.)
> Note that if your backend directly send emails, thoses emails can go into spam pretty much every time, and it takes a lot of ressoruces to process the email delevery, but this is a decision you can take based on how you want to send your emails.