?
Solved

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

Posted on 2012-03-31
9
Medium Priority
?
439 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

 
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
 
LVL 111

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 111

Accepted Solution

by:
Ray Paseur earned 2000 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

WordPress Tutorial 2: Terminology

An important part of learning any new piece of software is understanding the terminology it uses. Thankfully WordPress uses fairly simple names for everything that make it easy to start using the software.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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.
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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…
Suggested Courses

771 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