Solved

Trouble with a form requiring .php with a template I purchased

Posted on 2012-03-31
9
417 Views
Last Modified: 2012-04-01
Hello I was just wondering if you fellows could help me out with a problem I'm having. I don't have a great deal of understanding in .html and technically zero understanding in .php but apparently the website template I purchased did not come with the necessary code or files to direct my contact form to my email address.

Here is the code I have on my website currently:

                  <h2>Free Estimate Form</h2>
                  <form action="contact.php" id="contact-form">
                    <div class="wrapper">
                      <label>
                        <input type="text"  value="Name:" onBlur="if(this.value=='') this.value='Name:'" onFocus="if(this.value =='Name:' ) this.value=''" />
                      </label>
                      <label>
                        <input type="email"  value="E-mail:" onBlur="if(this.value=='') this.value='E-mail:'" onFocus="if(this.value =='E-mail:' ) this.value=''" />
                      </label>
                      <label>
                        <input type="text"  value="Phone:" onBlur="if(this.value=='') this.value='Phone:'" onFocus="if(this.value =='Phone:' ) this.value=''" />
                      </label>
                      <strong>
                      <textarea cols="1" rows="1" onBlur="if(this.value=='') this.value='Job:'" onFocus="if(this.value =='Job:' ) this.value=''" >Job Description:</textarea>
                      </strong>
                      <div class="clear"></div>
                      <a href="#" class="link" onClick="document.getElementById('contact-form').submit()"><span><span>Send</span></span></a> <a href="#" class="link" onClick="document.getElementById('contact-form').reset()"><span><span>Clear</span></span></a> </div>
                  </form>

I am trying to figure out how to make a contact.php for this so that I can place it in my website in order to receive emails regarding the information clients would fill in.

This is the link to the page:
http://www.deconenviro.com/index-5.html

Thanks,
Hope to hear from you guys soon.
0
Comment
Question by:Ted1984
  • 4
  • 3
  • 2
9 Comments
 
LVL 7

Expert Comment

by:designatedinitializer
ID: 37791628
First you must add a 'name' attribute to each form field. Like this:
<input type="text" name="name" value="Name:" onBlur="if(this.value=='') this.value='Name:'" onFocus="if(this.value =='Name:' ) this.value=''" />

The names you give your input fields are then enclosed in quotes, inside the square brackets in the $_POST variables at the beggining of your contact.php script, which will look like this:

<?php
$address = "you@yourdomain.com";
$subject  = "My contact form subject";
$name   = $_POST["name"];
$email   = $_POST["email"];
$phone  = $_POST["phone"];
$job       = $_POST["job"];

$msgtext = <<<TXT
Someone has sent you a message from the contact form.
Name: $name
Email: $email
Phone: $phone
Job description: $job
TXT

$headers = "From: ".mb_convert_encoding($sendername, "ISO-8859-1", "UTF-8")." <$email>" . "\r\n" .'X-Mailer: PHP/' . phpversion();
	$message = mail($address, mb_convert_encoding($subject, "ISO-8859-1", "UTF-8"),
					 mb_convert_encoding($msgtext, "ISO-8859-1", "UTF-8"),
					 $headers);
   if ($message) {?>
 
<!-- The message was sent. Put your HTML in here -->

 <?php } else { ?>

<!-- There was an error. Put corresponding HTML in here --> 

<?php   }
?>

Open in new window

0
 

Author Comment

by:Ted1984
ID: 37792334
Can this .php be a separate file on my file manager server or does it have to be placed within the code of my contacts page? I was just wondering whether my contacts.html page would retrieve this information if it was a separate file.
0
 

Author Comment

by:Ted1984
ID: 37792468
I've actually attempted to do what you stated. I edited the .html to include all of what you suggested and then made a .php file out of the code you gave me. I then placed the .php file and my website .html file separately but within the same directory on my website file manager, now when I go to send the form in I receive this error.

Parse error: syntax error, unexpected T_VARIABLE in /hermes/bosweb/web224/b2245/nf.deconenviro/public_html/deconenviro.com/contact.php on line 17

You can see for yourself here:

http://www.deconenviro.com/contact.html
0
 
LVL 7

Expert Comment

by:designatedinitializer
ID: 37793233
Hi,
You're doing great, it's just that first syntax I gave you is somewhat temperamental...
Try changing this:
$msgtext = <<<TXT
Someone has sent you a message from the contact form.
Name: $name
Email: $email
Phone: $phone
Job description: $job
TXT

Open in new window

to this:
$msgtext = "Someone has sent you a message from the contact form.\nName: $name\nEmail: $email\nPhone: $phone\nJob description: $job";

Open in new window

0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 108

Expert Comment

by:Ray Paseur
ID: 37793239
If you paid for this script, ask for your money back.  I'll try to show you how to fix this if you will post the PHP code for contact.php here.  Please use the code snippet feature, thanks.
0
 
LVL 108

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 37793306
Once we see your contact.php script we can get it fixed up for you.  Here is the form from the web page with all the "fluff" stripped away.  Note that I changed the action= attribute to use my own script and added the method=POST attribute to the form tag.  I also added the name= attributes to the input tags.
<h2>Free Estimate Form</h2>
<form method="post" action="RAY_temp_ted1984_contact.php" id="contact-form">
  <div class="wrapper">
    <label>
      <input type="text" name="n" value="Name:" onBlur="if(this.value=='') this.value='Name:'" onFocus="if(this.value =='Name:' ) this.value=''" />
    </label>
    <label>
      <input type="text" name="e" value="E-mail:" onBlur="if(this.value=='') this.value='E-mail:'" onFocus="if(this.value =='E-mail:' ) this.value=''" />
    </label>
    <label>
      <input type="text" name="p" value="Phone:" onBlur="if(this.value=='') this.value='Phone:'" onFocus="if(this.value =='Phone:' ) this.value=''" />
    </label>
    <strong>
    <textarea name="t" cols="1" rows="1" onBlur="if(this.value=='') this.value='Job:'" onFocus="if(this.value =='Job:' ) this.value=''" ></textarea>
    </strong>
    <div class="clear"></div>
    <a href="#" class="link" onClick="document.getElementById('contact-form').submit()"><span><span>Send</span></span></a> <a href="#" class="link" onClick="document.getElementById('contact-form').reset()"><span><span>Clear</span></span></a> </div>
</form>

Open in new window

Here is the action script that I used to test the form script.  It works correctly, sending me an email.
<?php // RAY_temp_ted1984_contact.php
error_reporting(E_ALL);

// ACTIVATE THESE TWO LINES TO SEE THE POST INFORMATION
// echo "<pre>";
// var_dump($_POST);

// THE EMAIL ADDRESS THAT WILL RECEIVE THE MESSAGE
$m = 'Ray.Paseur@Gmail.com';

// A FUNCTION TO CLEAN UP THE INFORMATION AND AVOID BECOMING AN OPEN-RELAY FOR SPAM
function clean_string($str)
{
    $rgx
    = '#'         // REGEX DELIMITER
    . '['         // CHARACTER CLASS
    . '^'         // NEGATION - MATCH NONE OF THESE ACCEPTABLE CHARACTERS
    . ' A-Z0-9_,?/@&*=()!\.\-'
    . ']'         // END OF CHARACTER CLASS
    . '#'         // REGEX DELIMITER
    . 'i'
    ;

    // ELIMINATE EXCESS WHITESPACE
    $str = trim(preg_replace('#\s\s+#', ' ', $str));

    // RETURN THE STRING - BAD CHARACTERS REPLACED WITH THE QUESTION MARK
    return preg_replace($rgx, '?', $str);
}

// CLEAN AND FORMAT THE INFORMATION
$n = clean_string($_POST['n']);
$p = clean_string($_POST['p']);
$e = clean_string($_POST['e']);
$t = clean_string($_POST['t']);

$w = $_SERVER["HTTP_HOST"];

// CREATE THE EMAIL MESSAGE
$b = <<<MESSAGE
Name: $n
Phone: $p
Email: $e
Message: $t
MESSAGE;

// SEND THE MESSAGE
mail($m, "Message from $w", $b);

Open in new window


Best regards, ~Ray
0
 

Author Comment

by:Ted1984
ID: 37793803
At the moment I am running this script as directed by Designated.

<?php
$address = "info@deconlogic.com";
$subject  = "Free Estimate Form";
$name   = $_POST["name"];
$email   = $_POST["email"];
$phone  = $_POST["phone"];
$job       = $_POST["job"];

$msgtext = "Someone has sent you a message from the contact form.\nName: $name\nEmail: $email\nPhone: $phone\nJob description: $job";

$headers = "From: ".mb_convert_encoding($sendername, "ISO-8859-1", "UTF-8")." <$email>" . "\r\n" .'X-Mailer: PHP/' . phpversion();
	$message = mail($address, mb_convert_encoding($subject, "ISO-8859-1", "UTF-8"),
					 mb_convert_encoding($msgtext, "ISO-8859-1", "UTF-8"),
					 $headers);
   if ($message) {?>
 
<!-- http://deconenviro.com/formsent2.html -->

 <?php } else { ?>

<!-- http://deconenviro.com/senderror2.html --> 

<?php   }
?>

Open in new window


And I am starting to receive an email at my destination however the email gives me empty information.

Someone has sent you a message from the contact form.
Name:
Email:
Phone:
Job description:

There must be something wrong in the method in which it is acquiring the inputs. I will try your solution also Ray and see how that works, but it is starting feel like this is almost complete.
0
 
LVL 7

Expert Comment

by:designatedinitializer
ID: 37793835
Please read carefully: you need to have 'name' attributes in each of your 'input' fields.
This means your <form> should look like this:
<form action="contact.php" id="contact-form">
                    <div class="wrapper">
                      <label>
                        <input type="text" name="name" value="Name:" onBlur="if(this.value=='') this.value='Name:'" onFocus="if(this.value =='Name:' ) this.value=''" />
                      </label>
                      <label>
                        <input type="email" name="email" value="E-mail:" onBlur="if(this.value=='') this.value='E-mail:'" onFocus="if(this.value =='E-mail:' ) this.value=''" />
                      </label>
                      <label>
                        <input type="text" name="phone" value="Phone:" onBlur="if(this.value=='') this.value='Phone:'" onFocus="if(this.value =='Phone:' ) this.value=''" />
                      </label>
                      <strong>
                      <textarea cols="1" name="job" rows="1" onBlur="if(this.value=='') this.value='Job:'" onFocus="if(this.value =='Job:' ) this.value=''" >Job Description:</textarea>
                      </strong>
                      <div class="clear"></div>
                      <a href="#" class="link" onClick="document.getElementById('contact-form').submit()"><span><span>Send</span></span></a> <a href="#" class="link" onClick="document.getElementById('contact-form').reset()"><span><span>Clear</span></span></a> </div>
                  </form>

Open in new window

0
 

Author Comment

by:Ted1984
ID: 37793943
I've managed to get it to work with your guys help it's just for some reason it has stopped sending the form to my email, and I haven't changed anything in the code. I haven't received the last 4 messages that I've attempted to send. What could possibly be the problem?
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now