Naomi Naomi - 8 months ago 32
HTML Question

Submit form with HTML and JS to email

I am using a form for people to submit contact requests for a website. I'm using JS and HTML for this website. I've tried to use mailto but it doesn't actually send anything to my email when I press submit. I don't want to use PHP if I can avoid it since I don't know PHP that well.

Here is my HTML

<form method=POST action="" enctype="text/plain">

<input type="text" name="companyname"><br>
Contact Person<br>
<input type="text" name="contactname"><br>
Phone number<br>
<input type="tel" name="phonenumber" min="6" max="15"><br>
<input type="email" name="email"><br>

<input type="textarea" name="message" style='white-space:pre-wrap; height:200px;width:500px;'><br>

<input type="submit" value="Submit">


I haven't done anything in the JS document for this to work. Do I have to use some sort of command for when submit is pressed in JS or should it be enough to do all this in HTML?


You cant send email directly using Javascript. For this you have to use php Mailing function, which has a very simple syntax.

// the message
$msg = "First line of text\nSecond line of text";

// use wordwrap() if lines are longer than 70 characters
$msg = wordwrap($msg,70);

// send email
mail("","My subject",$msg);