Page 1 of 1
I am new to PHP and need help Please
Posted: Tue Jul 19, 2011 5:48 am
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.
Re: I am new to PHP and need help
Posted: Tue Jul 19, 2011 8:30 am
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.
Re: I am new to PHP and need help Please
Posted: Tue Jul 19, 2011 11:20 am
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
Re: I am new to PHP and need help Please
Posted: Wed Jul 20, 2011 2:33 am
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
Didn't mean to post
Posted: Wed Jul 20, 2011 7:49 am
by RossDolan
a
Re: I am new to PHP and need help Please
Posted: Wed Jul 20, 2011 11:14 am
by Jonah Bron
Try uninstalling XAMPP and installing WAMP instead. And make sure you're accessing the file via
http://localhost/... .
Re: I am new to PHP and need help Please
Posted: Wed Jul 20, 2011 3:13 pm
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.
Re: I am new to PHP and need help Please
Posted: Wed Jul 20, 2011 5:22 pm
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.
Re: I am new to PHP and need help Please
Posted: Thu Jul 21, 2011 2:46 am
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!
Re: I am new to PHP and need help Please
Posted: Thu Jul 21, 2011 10:46 am
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
Re: I am new to PHP and need help Please
Posted: Fri Jul 22, 2011 3:04 am
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.
Re: I am new to PHP and need help Please
Posted: Fri Jul 22, 2011 6:59 am
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.
Re: I am new to PHP and need help Please
Posted: Mon Jul 25, 2011 8:41 am
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!
Re: I am new to PHP and need help Please
Posted: Mon Jul 25, 2011 1:27 pm
by Benjamin

Moved to PHP - Code
Re: I am new to PHP and need help Please
Posted: Fri Aug 05, 2011 6:29 am
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