|
|
|
|
![]() ![]() |
Jan 12 2006, 09:02 PM
Post
#1
|
|
|
Premium Member Group: Members Posts: 227 Joined: 25-April 05 Member No.: 4,369 |
So, now when I completely moved to another hosting and transfered all databases and stuff, I still have the LAST problem to fix. It's about the PHP contact form script
So I explain.. I've got a very simple contact form script which is composed of 3 different files: form.php - which determines the layout and which I have to include into my contact page config.php - where I set up the email adress where I want to receive the messages. sendmail.php - here's its code CODE <? include "config.php"; if ($f_name <> "" and $f_mail <> "" and $f_message <> "") { mail("$email", "$subject", "From: $f_name\nMail: $f_mail\nMessage:\n\n$f_message"); $msg = "Your message has been sent, thank you."; } else { $msg = "All fields are required, push the back button to fill out the rest."; } ?> <link href="forAll.css" rel="stylesheet" type="text/css"> CONTACT: <hr size="1"> <? echo $msg; ?> So, this little script worked perfectly, when I was with ASTAHOST... but now, when I moved to another hosting, I've just copied these 3 files from my old server and uploaded them to my new server, and when I wanted to test the contact form, I got the message as if I didn't fill all fields: "All fields are required, push the back button to fill out the rest. " Any idea how to fix that ? Please don't hesitate to drop a message Thanks. |
|
|
|
Jan 13 2006, 03:27 AM
Post
#2
|
|
|
Super Member Group: Members Posts: 572 Joined: 25-April 05 From: Nashville Tennessee Member No.: 4,340 |
Where is the form? I don't see one in that code, is it in the config.php?
|
|
|
|
Jan 13 2006, 11:44 AM
Post
#3
|
|
|
BUG.SWAT.PATROL Group: Members Posts: 626 Joined: 1-September 04 From: Auckland, New Zealand Member No.: 27 |
I take it you've come from a VB/MS background.
Anyways, most notable problem is with scripts being transferred to another server is the fact that your script was not written in the most compatable method. Make sure you use <?php ?> instead of <? ?> CODE <?php include_once('config.php'); if(!empty($fname) && !empty($f_mail) && !empty($f_message)){ mail($email, $subject, 'From: '.$f_name."\n".'Mail: '.$f_mail."\n".'Message:'."\n\n$f_message"); $msg = 'Your message has been sent, thank you.'; }else{ $msg = 'All fields are required, push the back button to fill out the rest.'; } ?> <link href="forAll.css" rel="stylesheet" type="text/css" media="all" /> <hr /> <?php echo $msg; ?> I also hope you're not using autoglobals, if so, the variables from your form will take on $_POST['fname']; that's if fname is the id/name of that field and the method of the form is post. So you'll probably want to do $fname = $_POST['fname']; etc to set those variables you use. Just make sure, full PHP tags, <?php ...code here... ?> Cheers, MC |
|
|
|
Jan 13 2006, 03:25 PM
Post
#4
|
|
|
Premium Member Group: Members Posts: 227 Joined: 25-April 05 Member No.: 4,369 |
Houdini, the form is in form.php file.. and I've only posted the sendmail.php code here.
mastercomputers, thanks for your reply, although after I used <?php ?> the problem is still there.. and about autoglobals, to be honest I didn't get it very well... I don't even know if I'm using autoglobals or not Could you please explain where I should put this $fname = $_POST['fname']; line in my code ? By the way, the metod is POST indeed... Also, something which looks very strange is that it worked very well with astahost hosting and now with the new hosting it doesn't... |
|
|
|
Jan 13 2006, 03:37 PM
Post
#5
|
|
|
[+] Graphic Designer [+] Group: Members Posts: 614 Joined: 6-April 05 From: Croatia Member No.: 3,666 |
QUOTE(Neverseen @ Jan 13 2006, 05:25 PM) Also, something which looks very strange is that it worked very well with astahost hosting and now with the new hosting it doesn't... You should check what's the difference between these two hostings, Astahost is on linux/unix, do your new hosting provider uses windows maybe? |
|
|
|
Jan 13 2006, 05:55 PM
Post
#6
|
|
|
Super Member Group: Members Posts: 572 Joined: 25-April 05 From: Nashville Tennessee Member No.: 4,340 |
There is a reason for wanting to see the form because that is where the sendmail.php is getting its values, most likely the config.php merely connects to the database and selects the database, but showing the program that processes the information it not of much value especially if the problem is not within that program but the program that tells it what values it is working with.
Basically speaking seeing what you have right now has nothing to work with and will do nothing because it depends on another program to tell it new information to process, if you have three programs and only show one of them it is hard to determine what is happening to the process as a whole. |
|
|
|
Jan 13 2006, 09:12 PM
Post
#7
|
|
|
BUG.SWAT.PATROL Group: Members Posts: 626 Joined: 1-September 04 From: Auckland, New Zealand Member No.: 27 |
Neverseen I think I answered your question with autoglobals/autoregister.
Anyways, you'll need to look at your form and take down all the attributes of 'id' or 'name' depending on how you wrote your form. e.g. CODE <form action="sendmail.php" method="post"> <p> <input type="text" id="fname" name="fname" /> <input type="submit" id="submit" name="submit" value="Submit" /> </p> </form> As you can see in the above, I'm using the post method in the form, and it's being directed to the sendmail.php page. The input elements each have an 'id' and 'name' pair of same value. If I was going to write a script for this ('I'm also including your other variables): CODE <?php include_once('config.php'); if(isset($_POST['submit'] && strpos($_POST['submit'], 'Submit')) { if(!isset($_POST('f_name') || !isset($_POST('f_mail') || !isset($_POST['f_message'])) { exit('All fields are required, push the back button to fill out the rest.'); }else{ $f_name = stripslashes(trim($_POST['f_name'])); $f_mail = stripslashes(trim($_POST['f_mail'])); $f_message = addslashes(trim($_POST['f_message'])); echo '<link href="forAll.css" rel="stylesheet" type="text/css" media="all" />'."\n".'<hr />'."\n"; } if(empty($f_name) || empty($f_mail) || empty($f_message)) { exit('Form fields can not be empty, push the back button to fill out the rest.'); } if(mail($email, $subject, 'From: ' . "$f_name\n" . 'Mail: ' . "$f_mail\n" . 'Message:' . "\n\n$f_message")) { echo 'Your message has been sent, thank you.'; }else{ exit('The message was not sent, please try again.'); } }else{ exit('You must use the supplied form.'); } ?> Because I've got a submit button, and the id/name = submit and the value = Submit, I first check whether this was set when posted, by checking if $_POST['submit'] is set, and then checking if it equals the value of 'Submit', there should be another security check though, which makes sure that the form actually is from us and not some forged form, but I left that out. I then check whether the variables that we sent through our form exist, and if not, I exit the script there instead of waiting till the end. I then store those variables in easier names, which is what you would have to do with your script by using the $form_id_name = $_POST['form_id_name']; way, which goes into the page that processes your form. After doing some trimming and removing slashes, I then check whether the variables are empty now and if they are I exit then and there. Next I send the mail, but I'm also making sure it is successful, since the mail function will return a boolean of true or false, if it was successful or not. The last line, pretty much represents what to do if the submit was not set or it did not equal the value Submit. To add more security to the script, you would define a constant in your form and you would check to make sure it's defined from your processing page. It also stops people trying to view the process page directly, but I think all you have to do to fix your code up is to make sure you use ids = $_POST['ids']; in your processing page, just define the lot of them. Cheers, MC |
|
|
|
Jan 13 2006, 11:43 PM
Post
#8
|
|
|
Premium Member Group: Members Posts: 227 Joined: 25-April 05 Member No.: 4,369 |
QUOTE(Houdini @ Jan 13 2006, 06:55 PM) There is a reason for wanting to see the form because that is where the sendmail.php is getting its values, most likely the config.php merely connects to the database and selects the database, but showing the program that processes the information it not of much value especially if the problem is not within that program but the program that tells it what values it is working with. Basically speaking seeing what you have right now has nothing to work with and will do nothing because it depends on another program to tell it new information to process, if you have three programs and only show one of them it is hard to determine what is happening to the process as a whole. Man, you know what ? You're 100% right ! It's all about form.php ! First of all, I'm happy to announce that I've solved the problem ! In fact, for some reason, my new hosting company decided that all their users should use the preinstalled script and shouldn't be able to use own ones and they were blocking my script (dunno how tbh), that's why it didn't work. So in my form.php file, instead of refering to sendmail.php I had to refere to their preinstalled script... and I also had to change some variables, because it changes a bit from my script. So now my last problem is solved ! Cheers! |
|
|
|
Jan 13 2006, 11:49 PM
Post
#9
|
|
|
Premium Member Group: Members Posts: 227 Joined: 25-April 05 Member No.: 4,369 |
mastercomputers, thanks for your time you spent here to explain the script !
thank you! |
|
|
|
Jan 14 2006, 11:10 PM
Post
#10
|
|
|
Super Member Group: Members Posts: 572 Joined: 25-April 05 From: Nashville Tennessee Member No.: 4,340 |
Glad you are set up with your new hosting site. One of the reasons that I asked about the form was if autoglobals are turned off or possibly you are using a server that has incorperated PHP5 some of your old scripts might not now work. So to fix that in the form lets say you have a value of
CODE $first_name_input in an input field, to make it work with PHP5 or autoglobal settings that you can not control then you would change it to CODE $_POST['first_name_input'] this will ensure that your code works. I run two servers on my local machine one running PHP5 and one running PHP4 and the reason for this is basically to test and be sure that any script that I write wil not only work on PHP4 but PHP5 also. Anyway I am glad you have your problem solved, but I am sure that as hosting sites start running PHP5 then there will need to be some code tweaking going on. |
|
|
|
![]() ![]() |
Similar Topics
|
Lo-Fi Version | Time is now: 8th September 2008 - 06:05 AM |