Neverseen 0 Report post Posted January 12, 2006 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 <?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 Xisto... 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. " But I DID fill them all ! I don't understand what it could be.. It worked very well with the other hosting and I didn't even touch to the code..but now with the new hosting it doesn't work.. Any idea how to fix that ? Please don't hesitate to drop a message Thanks. Share this post Link to post Share on other sites
Houdini 0 Report post Posted January 13, 2006 Where is the form? I don't see one in that code, is it in the config.php? Share this post Link to post Share on other sites
iGuest 3 Report post Posted January 13, 2006 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 <? ?> <?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 Share this post Link to post Share on other sites
Neverseen 0 Report post Posted January 13, 2006 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 I'm a total n00b with php, really! 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 Xisto hosting and now with the new hosting it doesn't... Share this post Link to post Share on other sites
finaldesign1405241487 0 Report post Posted January 13, 2006 Also, something which looks very strange is that it worked very well with Xisto hosting and now with the new hosting it doesn't... 1064335555[/snapback] You should check what's the difference between these two hostings, Xisto is on linux/unix, do your new hosting provider uses windows maybe? Share this post Link to post Share on other sites
Houdini 0 Report post Posted January 13, 2006 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. Share this post Link to post Share on other sites
iGuest 3 Report post Posted January 13, 2006 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. <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):<?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 Share this post Link to post Share on other sites
Neverseen 0 Report post Posted January 13, 2006 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. 1064335569[/snapback] 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 ! But in any case, thanks a lot to everyone who was trying to help me lately Cheers! Share this post Link to post Share on other sites
Neverseen 0 Report post Posted January 13, 2006 mastercomputers, thanks for your time you spent here to explain the script ! but as I've told in the previous post, I've solved the problem. Although I hope the things you've explained could be usefull for me later in php thank you! Share this post Link to post Share on other sites
Houdini 0 Report post Posted January 14, 2006 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 $first_name_inputin an input field, to make it work with PHP5 or autoglobal settings that you can not control then you would change it to $_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. Share this post Link to post Share on other sites
Neverseen 0 Report post Posted January 15, 2006 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 $first_name_inputin an input field, to make it work with PHP5 or autoglobal settings that you can not control then you would change it to $_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. 1064335717[/snapback] exactly, on my new hosting I can choose and switch between php4 and php5.. I don't know which one is better for me, but now I'm on PHP5 and everything works without any problem. Share this post Link to post Share on other sites