Jump to content

HTML Form - Submit using PHP


viathan

Recommended Posts

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

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";
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.