viathan Posted November 6, 2007 Share Posted November 6, 2007 I have a form that I made up in HTML but I need it to submit through PHP so I dont have to use the mailto: function. It has a flash movie at the top which is the menu bar, then on the bottom it has a form which has name, phone number, address, then a few more fields which include text boxes, a list of states in a drop down menu, check boxes and radio buttons. Can someone walk me through how to make the submit button go through php so that the form will email to my address without having my email in the code? Link to comment https://forums.phpfreaks.com/topic/76217-html-form-submit-using-php/ Share on other sites More sharing options...
trq Posted November 6, 2007 Share Posted November 6, 2007 You simply need to make the form's action point to your php script. Then, in the php script you coolect the data you want from the $_POST array, and send an email (I assume thats what your trying to do) using php's mail function. Link to comment https://forums.phpfreaks.com/topic/76217-html-form-submit-using-php/#findComment-385728 Share on other sites More sharing options...
revraz Posted November 6, 2007 Share Posted November 6, 2007 Example HTML <form method="POST" action="contact.php"> <p>Name:* <br /></p> <input type="text" name="Name"> <p>Comments:* <br /></p> <textarea name="Comments"></textarea> <p>Email:* <br /></p> <input type="text" name="Email"> <p><input type="submit" name="submit" value="Submit"></p> PHP <?php $EmailFrom = "FromEMail Address"; $EmailTo = "ToEMail Address"; $Subject = "YourSubject"; $Name = Trim(stripslashes($_POST['Name'])); $Comments = Trim(stripslashes($_POST['Comments'])); $Email = Trim(stripslashes($_POST['Email'])); // validation $validationOK=true; if (Trim($Name)=="") $validationOK=false; if (Trim($Comments)=="") $validationOK=false; if (Trim($Email)=="") $validationOK=false; if (!$validationOK) { print "Email Sent"; exit; } // prepare email body text $Body = ""; $Body .= "Name: "; $Body .= $Name; $Body .= "\n"; $Body .= "Comments: "; $Body .= $Comments; $Body .= "\n"; $Body .= "Email: "; $Body .= $Email; $Body .= "\n"; // send email $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>"); // redirect to success page if ($success){ print "Email Sent"; } else{ print "Error, Email not Sent"; } ?> Link to comment https://forums.phpfreaks.com/topic/76217-html-form-submit-using-php/#findComment-385794 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.