PHP help needed please

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

Contact Us

Please fill out the following form to contact us.

Your Name:
*required

Company Name:
*required

Phone Number:
*required

Your Email:
*required


Your Message:


PHP SCRIPT

<?php //Email Details $EmailFrom = "[email protected]"; $EmailTo = "[email protected]"; $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 ""; } else{ print ""; } ?>

Email Arrives like this:

Name: test
Company Name:
Phone Number:
Email: [email protected]
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!

Hi, and welcome to the forum!
I noticed you have wrong html form field names for Company and Phone Number:

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

See, field name in your form is “Company Name”, but this is not the same as “Company” what you use to populate data to email. So, you need to update to this:

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

And same with “Phone Number” —> make field name “Phone”

Hi there and thanks for your quick reply!

I’ve done as you kindly suggested but those two fields are still missing in the email i receive?

It’s almost like the company name and phone number fields are set to white text rather than black but i’ve checked this and all the fields are black text.

I overlooked one thing in your code. If register_globals is set Off in your php.ini (obviously it is), you need to add these lines, same as you have for other fields:

[php]$Company = trim(stripslashes($_POST[‘Company’]));
$Phone = trim(stripslashes($_POST[‘Phone’]));[/php]

I’ve added those lines of code in underneath the other lines and it still makes no difference? Very frustrating.

As for the php.ini file, the website is not hosted here so I don’t have access to that, or at least I’m guessing I don’t.

I am very new to php/html so sorry for being or sounding stupid!

Still not working? These lines need to be added above the code where you preparing email body text…

What is your form html code now, can you post here?

Hi sorry for the delay, here it is:

HTML FORM

Contact Us

Please fill out the following form to contact us.

Your Name:
*required

Company Name:
*required

Phone Number:
*required

Your Email:
*required


Your Message:


PHP SCRIPT

<?php //Email Details $EmailFrom = "*********"; $EmailTo = "**********"; $Subject = "Website Contact Form Submission"; $Name = trim(stripslashes($_POST['Name'])); $Email = trim(stripslashes($_POST['Email'])); $Comments = trim(stripslashes($_POST['Comments'])); $Company = trim(stripslashes($_POST['Company'])); $Phone = trim(stripslashes($_POST['Phone'])); // 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 ""; } else{ print ""; } ?>

Company and Phone fields in your code are now fine - they should be displayed in email, just same as all other fields. There is no reason for Company/Phone fields to not appear in email in other fields appear. Make sure you’re editing right file, not backed up copy :slight_smile:

Thanks for looking for me.

Is there anyway i can edit my original post as i’ve accidently posted 2 actual email addresses and i need to remove them.

It still comes through with the two fields missing for some reason and I don’t know enough about these things to understand why. They are definitly not the backup files.

For debugging purpose, try to replace this line:
[php]$Body .= $Company;[/php]

to this:
[php]$Body .= ‘Hello World!’;[/php]

and check if something will change in the email what you receive. Because if other fields are working, there is NO reason why would company or phone field would not work, because they are treated the same as any other field in your code.

Thanks to you both for helping! Sorted it!

After doing what php coder suggested i was still using my hotmail account to test and it was blocking some of the content! Now it works with the actual email account so a big big thanks for your input.

If I need more help (as im working on other parts of the website) I know where to come :smiley:

Sponsor our Newsletter | Privacy Policy | Terms of Service