Jump to content

PHP help needed please


toulsonguk

Recommended Posts

Hey all

 

Sorry for becoming a new member and then pasting this but I've started a new job in I.T and I've been asked to work on the company website even though I have no idea about PHP/HTML so I need to become a fast learner! Any help will be muchly appreciated.

 

Basically on the contact us form on the website, a PHP script emails us the form which works fine except it misses out two lines which is should have filled in? I cannot see any errors and dreamweaver reports that the syntax is all good.

 

Would somebody mind taking a look at the coding and see if you can spot anything wrong?

 

HTML FORM

 

<h1>Contact Us</h1>

        <p>Please fill out the following form to contact us.</p>

        <form id="contactform" method="post" action="contactengine.php">

          <p>

            <label for="Name" >Your Name:</label>

            <br />

            <input type="text" name="Name" id="Name" class="inputValue"/>

            <span class="required">*required</span><br />

            <br />

            <label for="Email" >Company Name:</label>

            <br />

            <input type="text" name="Company Name" id="Company" class="inputValue"/>

            <span class="required">*required</span><br />         

            <br />

            <label for="Email" >Phone Number:</label>

            <br />

            <input type="text" name="Phone Number" id="Phone" class="inputValue"/>

            <span class="required">*required</span><br />

            <br />

            <label for="Email" >Your Email:</label>

            <br />

            <input type="text" name="Email" id="Email" class="inputValue" />

            <span class="required">*required</span><br />

          </p>

      <br />

            <label for="Comments" >Your Message:</label>

            <br />

            <textarea name="Comments" cols="45" rows="8" class="inputText" id="Comments" ></textarea>

            <br />         

            <br />

            <input type="submit" value="Submit" class="inputButton"/>

          </p>

</form>

 

PHP SCRIPT

 

<?php

 

//Email Details

 

$EmailFrom = "someone@nowhere.com";

$EmailTo = "someone@nowhere.com";

$Subject = "Website Contact Form Submission";

 

$Name = Trim(stripslashes($_POST['Name']));

$Email = Trim(stripslashes($_POST['Email']));

$Comments = Trim(stripslashes($_POST['Comments']));

 

// prepare email body text

 

$Body .= "Name: ";

$Body .= $Name;

$Body .= "\n";

$Body .= "Company Name: ";

$Body .= $Company;

$Body .= "\n";

$Body .= "Phone Number: ";

$Body .= $Phone;

$Body .= "\n";

$Body .= "Email: ";

$Body .= $Email;

$Body .= "\n";

$Body .= "Message: ";

$Body .= $Comments;

$Body .= "\n";

 

// send email

$success = mail($EmailTo,$Subject,$Body, "From: <$EmailFrom>");

 

// redirect to success page

// CHANGE THE URL BELOW TO YOUR "THANK YOU" PAGE

if ($success){

  print "<meta http-equiv=\"refresh\" content=\"0;URL=contactthanks.html\">";

 

}

else{

  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.html\">";

 

}

?>

 

Email Arrives like this:

 

Name: test

Company Name:

Phone Number:

Email: test@test.com

Message: sdfdsfs

 

Basically the email arrives as shown but it's missing the Phone Number and Company name details? I think this code has been borrowed when the website made so it's been changed to suite our needs.

 

Thanks for taking the time to look at this!

 

Link to comment
Share on other sites

$phone and $company do not have any value inherently. They must receive values sent to the script from the form by the method POST.

 

Look here:

$Name = Trim(stripslashes($_POST['Name']));
$Email = Trim(stripslashes($_POST['Email']));
$Comments = Trim(stripslashes($_POST['Comments'])); 

 

This is where the variables $name, $email and $comments receive values based on the form values that have been POST'd to the script.

 

There is no space for $phone or $company. You could solve this easily by appending

$Phone = Trim(stripslashes($_POST['Phone']);
$Company = Trim(stripslashes($_POST['Company']);

 

Also, look at your form. It's a little copy and pasted, I can tell that.  ;D

 

            <label for="Email" >Company Name:</label>
            <br />
            <input type="text" name="Company Name" id="Company" class="inputValue"/>
            <span class="required">*required</span><br />         
            <br />
            <label for="Email" >Phone Number:</label>
            <br />
            <input type="text" name="Phone Number" id="Phone" class="inputValue"/>
            <span class="required">*required</span><br />

 

needs to become

 

            <label for="Company" >Company Name:</label>
            <br />
            <input type="text" name="Company" id="Company" class="inputValue"/>
            <span class="required">*required</span><br />         
            <br />
            <label for="Phone" >Phone Number:</label>
            <br />
            <input type="text" name="Phone" id="Phone" class="inputValue"/>
            <span class="required">*required</span><br />

 

The name attribute is what is used by $_POST, iirc.

 

< /lecture>

 

Here's two functions that can make learning a lot easier. var_dump or print_r.

You could do a var_dump($_POST); or print_r($_POST); to get everything inside of that variable. Also if you're really in a pinch, there are many PHP tutorials on the 'net as well as youtube. You could also outsource it! A simple thing like that wouldn't have cost very much.

 

Happy scripting!

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.