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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.