Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Making a PHP Contact Form
email twitter facebook digg delicious stumbleupon reddit linkedin blogger googlebuzz myspace orkut tumblr slashdot technorati wordpress more
09-10-2012, 11:08 PM (This post was last modified: 09-14-2012 05:44 AM by Dave.)
Post: #1
Making a PHP Contact Form
If you recently purchased one of Squidix LLC's themes, you may have noticed that we have not completed the contact form function. This is because you will need to input a PHP file for it to work. As this is a HTML/CSS3 template, we have not implemented this addition. In order to assist you in making your contact form work, we have posted this tutorial to help you, step by step, set up your system for your new template.

If you have any questions, you may contact us directly by responding to this post or by sending a ticket to our support department from the client area.

The first thing that you will need to do is replace the current form in your template with the one below. Please note that this tutorial is based on Construct, our newest template, and you may need to adjust certain settings depending on the template.

Your current form HTML code will look like this:

Code:
<form action="#" method="post">
    <p><label for="namet">Name</label>(required)<br /><input id="namet" type="text" /></p>
    <p><label for="mailt">E-mail</label>(required)<br /><input id="mailt" type="text" /></p>
    <p><label for="website">Website</label><br /><input id="website" type="text" /></p>
    <p><label for="message">Message</label>(required)<br /><textarea id="message"></textarea></p>
    <p><input class="btn_m" type="submit" value="Submit Form" /></p>
</form>

Replace it with:


Code:
<form action="mail.php" method="post">
    <p><label for="namet">Name</label>(required)<br /><input name="name" id="namet" type="text" /></p>
    <p><label for="mailt">E-mail</label>(required)<br /><input name="mail" id="mailt" type="text" /></p>
    <p><label for="website">Website</label><br /><input name="website" id="website" type="text" /></p>
    <p><label for="message">Message</label>(required)<br /><textarea name="message" id="message" ></textarea></p>
    <p><input class="btn_m" type="submit" value="Submit Form" /></p>
</form>

We have adjusted the name values so that the PHP file, which you will create in the next step, will execute properly. We have also changed the action attribute in order to allow the system to read the PHP script and execute the process.

Next, make a new file in the directory that the theme is on (usually "/"). This file will be named "mail.php" DO NOT ADD .html! It will not function properly, simply put "mail.php"

Place the following script in this file:

PHP Code:
<?php
if ($_POST["mail"]<>'') {
    
$ToEmail 'youremail@yoursite.com';
    
$EmailSubject 'Contact Form';
    
$mailheader "From: ".$_POST["mail"]."\r\n";
    
$mailheader .= "Reply-To: ".$_POST["mail"]."\r\n";
    
$mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n";
    
$MESSAGE_BODY "Name: ".$_POST["name"]."\r\n";
    
$MESSAGE_BODY .= "Email: ".$_POST["mail"]."\r\n";
    
$MESSAGE_BODY .= "Comment: ".$_POST["message"]."\r\n";
    
mail($ToEmail$EmailSubject$MESSAGE_BODY$mailheader) or die ("Failure");
    echo 
'We got your submission!';
}
?>

As you can see, you will need to enter your e-mail.

You may also refer people to a URL instead of simply showing them an image by changing the echo "We got your submission!"; to header("location:thanks.html"); or another page to signify your thanks or that you got the message.

That's it! You're ready to receive your information from consumers!
Find all posts by this user
Quote this message in a reply
09-24-2012, 07:46 AM (This post was last modified: 09-24-2012 07:47 AM by nazardo.)
Post: #2
RE: Making a PHP Contact Form
Hi,
I have construct, I followed this tutorial but it doesn't works.
After click on Submit Form button, the browser prompts the code of mail.php as follow:
<?php
if ($_POST["mail"]<>'') {
$ToEmail = 'xxx@yyy.com';
$EmailSubject = 'Contact Form';
$mailheader = "From: ".$_POST["mail"]."\r\n";
$mailheader .= "Reply-To: ".$_POST["mail"]."\r\n";
$mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n";
$MESSAGE_BODY = "Name: ".$_POST["name"]."\r\n";
$MESSAGE_BODY .= "Email: ".$_POST["mail"]."\r\n";
$MESSAGE_BODY .= "Comment: ".$_POST["message"]."\r\n";
mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure");
echo 'We got your submission!';
}
?>
Find all posts by this user
Quote this message in a reply
09-25-2012, 07:43 AM
Post: #3
RE: Making a PHP Contact Form
nazardo,

that means your server is not enabled for php properly. The code is not being interpreted and executed.

Sam Barrow
You have enemies? Good. That means you've stood up for something, sometime in your life.
Visit this user's website Find all posts by this user
Quote this message in a reply
09-25-2012, 09:39 AM
Post: #4
RE: Making a PHP Contact Form
(09-25-2012 07:43 AM)Sam Barrow Wrote:  nazardo,

that means your server is not enabled for php properly. The code is not being interpreted and executed.
Thanks Sam!

I will install PHP for IIS and I will put my website on IIS
Before I work directly in my PC using ExpressionWeb without using a webserver Blush
Find all posts by this user
Quote this message in a reply
Post Reply 


Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Sending Form Data Via Email To Your Email Address! CRiches 1 1,219 05-03-2011 08:19 AM
Last Post: colo

Forum Jump:


User(s) browsing this thread: 1 Guest(s)