Welcome Guest ( Log In | Register )



2 Pages V   1 2 >  
Reply to this topicStart new topic
> Contact Form Script Trouble
Neverseen
post Jan 12 2006, 09:02 PM
Post #1


Premium Member
Group Icon

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. " blink.gif 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 smile.gif

Thanks.
Go to the top of the page
 
+Quote Post
Houdini
post Jan 13 2006, 03:27 AM
Post #2


Super Member
Group Icon

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?
Go to the top of the page
 
+Quote Post
mastercomputers
post Jan 13 2006, 11:44 AM
Post #3


BUG.SWAT.PATROL
Group Icon

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
Go to the top of the page
 
+Quote Post
Neverseen
post Jan 13 2006, 03:25 PM
Post #4


Premium Member
Group Icon

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 biggrin.gif 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 astahost hosting and now with the new hosting it doesn't...
Go to the top of the page
 
+Quote Post
finaldesign
post Jan 13 2006, 03:37 PM
Post #5


[+] Graphic Designer [+]
Group Icon

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? huh.gif
Go to the top of the page
 
+Quote Post
Houdini
post Jan 13 2006, 05:55 PM
Post #6


Super Member
Group Icon

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.
Go to the top of the page
 
+Quote Post
mastercomputers
post Jan 13 2006, 09:12 PM
Post #7


BUG.SWAT.PATROL
Group Icon

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
Go to the top of the page
 
+Quote Post
Neverseen
post Jan 13 2006, 11:43 PM
Post #8


Premium Member
Group Icon

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 ! biggrin.gif

First of all, I'm happy to announce that I've solved the problem ! tongue.gif

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 ! biggrin.gif But in any case, thanks a lot to everyone who was trying to help me lately wink.gif

Cheers!
Go to the top of the page
 
+Quote Post
Neverseen
post Jan 13 2006, 11:49 PM
Post #9


Premium Member
Group Icon

Group: Members
Posts: 227
Joined: 25-April 05
Member No.: 4,369



mastercomputers, thanks for your time you spent here to explain the script ! smile.gif 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 wink.gif
thank you! smile.gif
Go to the top of the page
 
+Quote Post
Houdini
post Jan 14 2006, 11:10 PM
Post #10


Super Member
Group Icon

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.
Go to the top of the page
 
+Quote Post

2 Pages V   1 2 >
Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Trainable Anti-spam Filter Script(3)
  2. Php Script To Download File From Another Site(9)
  3. Need Help With A PHP - MySQL Registration Script(13)
  4. What Would Make A Good Registration Script?(4)
  5. Auto Responder Script(6)
  6. Blog Script?(5)
  7. Installed A PR Checker Script - But Not Working Correctly(6)
  8. How To Delete File Using PHP Shell Script(3)
  9. Online Multiplayer Chess Script(2)
  10. Automated File Structure Creation Script(3)
  11. Authentication Script(1)
  12. Login Script(5)
  13. Please Help (php Join Script)(5)
  14. Automatic/remote Php Script Execution(9)
  15. Something Wrong With This Script?(9)
  1. Automated Product Suggestion Script(2)
  2. Run A Script When Expires A Session(6)
  3. Php Script Help(1)
  4. SQL Doesn't Connect In PHP Script(19)
  5. Warning: Mysql_result(): Supplied Argument Is Not A Valid Mysql Result Resource In ...(4)
  6. Password Recovery Script(6)
  7. Login Script(8)
  8. Free Forum Hosting Type Script Help!(2)
  9. Script Request(2)
  10. Writing And Testing My Own Login Script [solved](20)
  11. Make A Script Run Even If No User Is Online(6)
  12. Php Login Script(0)
  13. Myspacetv Download Php Script Help(6)


 



- Lo-Fi Version Time is now: 8th September 2008 - 06:05 AM