I am new to PHP and need help Please

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
RossDolan
Forum Commoner
Posts: 31
Joined: Tue Jul 19, 2011 5:44 am

I am new to PHP and need help Please

Post by RossDolan »

I am trying to create a form which submits an email using php, the code is below:

Code: Select all

<?php

$to = $_REQUEST['Query'];
$from = $_REQUEST['Email Address'];
$name = $_REQUEST['Fullname'];
$headers = "From: $from";
$subject = "Web Contact Data"; 

$fields = array();
$fields {"Fullname"} = "Name"; 
$fields {"Email Address"} = "Email";
$fields {"Telephone Number"} = "Phone";
$fields {"Mobile Number"} = "Mobile";
$fields {"Message"} = "Message"; 

$body = "We have received the following information: \n\n"; foreach($fields as $a => $b){$body .= sprintf("%20s: %s\n", $b,$_REQUEST[$a]);}

$headers2 = "From: noreply@mycompany.com";
$subject2 = "Thank you for contacting us"; 
$autoreply = "Thank you for contacting us. One of our representatives will be in touch with you within the next 48 hours.";

if($from == '') {print "You have not entered an email, please go back and try again.";}
else{
	if($name == '') {print "You have not entered a name, please go back and try again";}
	else{
		$send = mail($to, $subject, $body, $headers);
		$send2 = mail ($from, $subject2, $autoreply, $headers2);
if(send){header("Location: http:///www.mycompany.com/thankyou.html");}
else (print "We encountered an error sending your email, please give us a call on 0000 000 0000");}
}
}
?>
However when I press the send button on the form it prints out all the code instead of actually doing anything, this has happened with a few php documents I have created.

Any help would be appreciated.
Last edited by Benjamin on Mon Jul 25, 2011 1:26 pm, edited 2 times in total.
Reason: Added [syntax=php|sql|css|javascript] and/or [text] tags.
RossDolan
Forum Commoner
Posts: 31
Joined: Tue Jul 19, 2011 5:44 am

Re: I am new to PHP and need help

Post by RossDolan »

Anyone? Getting desperate now as I said I would do this for my mates company and at the time didn't realise PHP wasn't working properly. Again any help or advice would be appreciated.
beetree
Forum Commoner
Posts: 26
Joined: Mon Jul 18, 2011 6:30 pm
Location: Peninsula

Re: I am new to PHP and need help Please

Post by beetree »

1. Make sure you have named the file ".php".

2. If it still doesn't work, try creating a file that is named "test.php" that contains the following:

<?php phpinfo(); ?>

3. If test.php still doesn't output anything, you probably haven't installed PHP. Please provide the following information: server operating system, webserver, location of your PHP source code, installation and php.ini file, and we will try to help you.

Best,
Beetree
RossDolan
Forum Commoner
Posts: 31
Joined: Tue Jul 19, 2011 5:44 am

Re: I am new to PHP and need help Please

Post by RossDolan »

Thanks for getting back to me,

I tried the test.php and nothing was returned.

I am using XAMPP on windows 7. I was using a localhost so that I could test it all before sending it to my mate. I tried attaching the php.ini document but it is saying .ini extensions are not allowed, also tried attaching it as a txt file but again it was not allowed. I also tried pasting the text from it on here but it exceeded the maximum characters. Not sure how to get the file to you.

It is probably something glaringly obvious that I am doing wrong but I have no idea, the thing that gets me is that it was working fine until a couple of weeks ago when I was working through a PHP book doing examples and then all of a sudden it stopped working.

I do apologise if the info above is rubbish, still pretty new to this. If its wrong let me know.

Cheers
Ross
RossDolan
Forum Commoner
Posts: 31
Joined: Tue Jul 19, 2011 5:44 am

Didn't mean to post

Post by RossDolan »

a
Last edited by RossDolan on Wed Jul 20, 2011 3:07 pm, edited 1 time in total.
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: I am new to PHP and need help Please

Post by Jonah Bron »

Try uninstalling XAMPP and installing WAMP instead. And make sure you're accessing the file via http://localhost/... .
RossDolan
Forum Commoner
Posts: 31
Joined: Tue Jul 19, 2011 5:44 am

Re: I am new to PHP and need help Please

Post by RossDolan »

Cheers for that, I'll give it a try. Does anyone have any suggestions about why this may have happened? PHP was working fine then all of a sudden stopped. I have also noticed that there is a file in htdocs called index.php, it states that there is a problem with the xampp installation but was working fine before? Any suggestions?

Again any help is appreciated.
Doug G
Forum Contributor
Posts: 282
Joined: Sun Sep 09, 2007 6:27 pm

Re: I am new to PHP and need help Please

Post by Doug G »

xampp has a nice service monitor, does it show the necessary services are running? If so, can you open phpmyadmin from the xampp monitor menu? I have xampp on windows 7 without problems.
RossDolan
Forum Commoner
Posts: 31
Joined: Tue Jul 19, 2011 5:44 am

Re: I am new to PHP and need help Please

Post by RossDolan »

I have had a look at the XAMPP Control Panel and Apache and MySql are both running. When I go into http://localhost/xampp/ I can access phpmyadmin no problem. The problem occurs when I create a PHP file on dreamweaver and try to run it - instead of actually processing the code it prints everything out. A couple of people have suggested it may not be installed correctly. I have run the <?php phpinfo(); ?> code and nothing was returned so I don't think it is installed correctly. However it was installed and working fine up until a couple of weeks ago. Its a strange one!
Doug G
Forum Contributor
Posts: 282
Joined: Sun Sep 09, 2007 6:27 pm

Re: I am new to PHP and need help Please

Post by Doug G »

If you can run phpmyadmin on the machine then apache and php must be working. Perhaps you're putting your dreamweaver files in a directory that's not known to apache? Find out the directory root of your apache server (it's shown in the apache conf file), and place your phpinfo script in that directory and try running it by opening a web browser to localhost/myphpinfo.php
RossDolan
Forum Commoner
Posts: 31
Joined: Tue Jul 19, 2011 5:44 am

Re: I am new to PHP and need help Please

Post by RossDolan »

Doug G,

I tried saving the test.php (phpinfo) file into the apache htdocs and still no luck. One thing I have noticed is that when I used to use this and went onto localhost it gave me a list of the different projects I had saved and an option for xampp, so I could go in and look at all my files before going into xampp to look at the databases. Sorry if all this seems stupid, I'm still pretty new to all of the this, first time anything has went wrong lol. Again any help is appreciated.
RossDolan
Forum Commoner
Posts: 31
Joined: Tue Jul 19, 2011 5:44 am

Re: I am new to PHP and need help Please

Post by RossDolan »

Sorry forgot to mention, I have copied the htdocs file form the xampp folder and put it on my desktop, I created a file in there for my website and it is sitting in the xampp and desktop folders. When I done it this way before I was able to view the files on localhost as well as having the option to go into xampp as mentioned above. Cheers in advance for any help.
RossDolan
Forum Commoner
Posts: 31
Joined: Tue Jul 19, 2011 5:44 am

Re: I am new to PHP and need help Please

Post by RossDolan »

Thanks everyone for your help, I managed to get it working. It was because there was no directory set up in the htdocs file so xampp couldn't retrieve the website as it didn't know it was there. Up and running now. Cheers. I'll no doubt be back on the forum soon!
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: I am new to PHP and need help Please

Post by Benjamin »

:arrow: Moved to PHP - Code
felixcristober
Forum Newbie
Posts: 1
Joined: Fri Aug 05, 2011 6:13 am

Re: I am new to PHP and need help Please

Post by felixcristober »

if u click the send button,
first where u set the function of send.
send is function name write then where u call the function.
correctly u call the function it's working



web development solutions
Post Reply