Jump to content

PHP - Web forms handling


robmo

Recommended Posts

Hi,

 

I have an HTML form created using Dreamweaver and now I need a script to handle the form processing. Basically what I need is for the form data received from the webpage to be organized in an email and then sent to me. I would also like to display a thank you message in the browser so the user knows it was received. I was planning to do this using CGI but a colleague suggested that CGI is old school and nowadays a developer would use PHP for this task. Is PHP the right solution for this project?

 

The examples I have found so far always include the HTML for the form and the script needed to handle it in one file. In my case, I have an HTML form already in place and need it to work with a script to perform the email function. I know I need to set "Action=" on my webpage to point to the PHP script but what would the code look like if no HTML is needed? I hope this makes sense...

 

Thanks for your help!

Rob

Link to comment
Share on other sites

My form is located at the link below. It doesn't do anything yet as there is no code available to process the form. I have spent some time looking for examples and I see that there are many but of course, they don't meet my needs and require editing. My main question is if PHP is the solution by today's standards.

 

http://www.tallfirshoa.com/adform.htm

 

Link to comment
Share on other sites

<?php 
if(isset($_POST['submit'])) { 
$to = "someemail@example.com";
$subject = "Your subject"; 
$fname = $_POST['fname']; 
$lname = $_POST['lname']; 
$email = $_POST['email'];
$displayemail = $_POST['displayemail']; 
$phone = $_POST['phone']; 
$category = $_POST['category']; 
$description = $_POST['description']; 
$headers = "From: $email \r\n 
            Reply-To: $email";
   
$body = "From: $fname $lname\n E-mail: $email\n Display Email on website: $displayemail\n Phone: $phone\n Category: $category\n Description:\n $description"; 

echo "Dear $fname $lname, <br/> Your Information<br/> E-mail: $email, <br/> Display Email on website: $displayemail, <br/>Phone: $phone, <br/>Categoty: $category, <br/>Description: $description <br/><br/> has been submitted successfully to us!"; 
mail($to, $subject, $body, $headers);
} else { 
echo "Error!";
} 

?>

Link to comment
Share on other sites

Well, I wasn't really asking you to code this for me but thank you so much! I can easily see now how this is done. I just found it very confusing with the HTML intermixed with the PHP code. I'm obviously not a PHP developer but I do write code in other languages.

 

Thanks again!

 

Rob

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.