Form Processors?

Status
Not open for further replies.

Ben89

New member
Mar 30, 2007
670
4
0
Hey guys, I've got the HTML down when it comes to building forms but I really need a form processor to send over that data to my email because I don't know much PHP.

Please let me know if you guys have any scripts to do this.

Thanks.
 


Hey guys, I've got the HTML down when it comes to building forms but I really need a form processor to send over that data to my email because I don't know much PHP.

Please let me know if you guys have any scripts to do this.

Thanks.

PhPMailer if you want something a lil more customizable than using PHP's built in mail function.

I could quickly set something up for ya if you want :D

In a nutshell
http://www.php.net/manual/en/function.mail.php

Code:
<?php
// The message
$message = "Line 1\nLine 2\nLine 3";

// In case any of our lines are larger than 70 characters, we should use wordwrap()
$message = wordwrap($message, 70);

// Send
mail('caffeinated@example.com', 'My Subject', $message);
?>

But you'd modify it to take the message from say $_POST['message']; if the message box was a <textarea name="message" id="message" ...></textarea>
 
I see, but how exactly does the html page with the forms communicate with the php script, in other words if the script is called script.php on my server, how does the my webpage make use of script.php to email the data in the forms?
 
As I mentioned, via $_POST, $_GET or $_REQUEST.

For example, if your form is using method="post", and you have an input for email. with a name/id of "your_email", then on the PHP side, you would have

$email = $_POST["your_email"];

Course if no email was passed it'll simply be blank, so it'll be up to you to validate the information being passed to the PHP script (preferably both on the javascript side and php side).

If you were to make up a form with the desired fields, and the email where to send it to, I'll make convert it to a self-calling php script to send the submitted information... for 10$ :P
 
Here is a simple form and processor to send you an email. You can easily add additional values to the form page and the processor.

form page (with javascript for required fields):
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>form</title>

<!-- 
script to validate required form fields
add/replace values inside document.contact[""]
-->
<script type="text/javascript"> 
function verifyRequired() {
  if (document.contact["name"].value == "") {
    alert("Please enter your name.");
    return false;
  }
  if (document.contact["email"].value == "") {
    alert("Please enter your email address.");
    return false;
  }
return true;
}
</script>

</head>

<body>

<form action="contact.php" method="post" name="contact" onsubmit="return verifyRequired();">
Name: <input name="name" type="text" /><br/>
Email: <input name="email" type="text" /><br/>
<input name="" type="submit"/>
</form>

</body>
</html>
form processor, with redirect to thank you page:
Code:
<?php 

// -------------------------------
// simple form processor
// somlor - wickedfire 2009
// -------------------------------

if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
 $ClientIP = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
 $ClientIP = $_SERVER['REMOTE_ADDR'];
}

$name = $_REQUEST['name'];
$email = $_REQUEST['email'];
// add new variables, requesting data from your additional form inputs here

// send email with form data
$emailSubject = "form submission";
$emailBody = "Form details:\n"
 . "\n"
 . "Name : $name\n"
 . "Email : $email\n"
// add your additional variables here, so you receive the data in your email
 . "\n"
 . "IP : $ClientIP\n";

$emailTo = "myemail@whatever.com"; // email form will be sent to
$emailFrom = "myemail@whatever.com"; // email form will be sent from (doesn't matter, usually keep the same as emailTo)
  
$emailHeader = "From: $emailFrom\n"
  . "MIME-Version: 1.0\n"
  . "Content-type: text/plain; charset=\"ISO-8859-1\"\n"
  . "Content-transfer-encoding: 8bit\n";

mail($emailTo, $emailSubject, $emailBody, $emailHeader);

// redirect to thank you page
header('Location: thanks.html'); // put URL to your thank you page here
exit;
?>
 
I appreciate the help from you guys +rep but I have some questions about the php script from somlor.

What should go in place of the first and second "HTTP_X_FORWARDED_FOR" and "REMOTE_ADDR"

Also, does this script need to uploaded to a certain section of my server or do I just place it in the main directory.

Lastly, if you guys can recommend some good PHP textbooks that explain the fundamentals with very practical applications in building interactive webpages, I would appreciate it.

Thanks.
 
(I'll look something up on books if someone else doesn't respond before hand).

Far as where to put the php script. I typically place it into the same folder as the contact form. Course most of the contact forms I've written, the form and the processor were the same php files calling itself (it would check to see if the form been submitted to itself then process it, otherwise shows the form).

Far as the HTTP_X_ And so forth. Thats just to log the client's IP address or hostname that they visited your site with. You wouldn't change those nor try to put them in the form. They're server environment variables.
 
Easier than copying, pasting and editing the above... download FormsToGo and make a few clicks.

It's not almighty but it does the job.
 
Easier than copying, pasting and editing the above... download FormsToGo and make a few clicks.

It's not almighty but it does the job.
Yeah, hah, that's exactly where I got the original processor code above. Nowadays I prefer to just manually tweak the code above unless I'm working with a huge form with tons of complex fields. Then I'll throw it into FormsToGo, good little program.

Sean
 
^^Yeah, thats it. Its pretty easy and I recall it has decent instructions so even if you are not too techy you should be able to figure it out fine.
 
Status
Not open for further replies.