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!
<?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.
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.
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.
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 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?
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.
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!
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
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.
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.
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!
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