gazfocus Posted September 20, 2008 Share Posted September 20, 2008 I am trying to make a simple PHP form to have in place while I am building a website for a friend, but when I tried the form on my domain, it works perfectly (www.citycm.co.uk/rainbow.php), however, when I then upload it to my friends server, it comes up with 3 errors (www.rainbowchildcare.org.uk/rainbow.php). Does anyone have any ideas as to why this is happening? Or even better, does anyone have any solutions? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/125074-solved-php-form-working-on-one-server-but-not-another/ Share on other sites More sharing options...
waynew Posted September 20, 2008 Share Posted September 20, 2008 What are the errors you are getting? Quote Link to comment https://forums.phpfreaks.com/topic/125074-solved-php-form-working-on-one-server-but-not-another/#findComment-646381 Share on other sites More sharing options...
gazfocus Posted September 20, 2008 Author Share Posted September 20, 2008 What are the errors you are getting? If you go to www.rainbowchildcare.org.uk/rainbow.php you will see the errors there: Notice: Use of undefined constant viewed - assumed 'viewed' in E:\domains\r\rainbowchildcare.org.uk\user\htdocs\rainbow.php on line 32 Notice: Undefined index: viewed in E:\domains\r\rainbowchildcare.org.uk\user\htdocs\rainbow.php on line 32 Notice: Undefined variable: SERVER in E:\domains\r\rainbowchildcare.org.uk\user\htdocs\rainbow.php on line 34 Quote Link to comment https://forums.phpfreaks.com/topic/125074-solved-php-form-working-on-one-server-but-not-another/#findComment-646383 Share on other sites More sharing options...
waynew Posted September 20, 2008 Share Posted September 20, 2008 Could you post the code? Quote Link to comment https://forums.phpfreaks.com/topic/125074-solved-php-form-working-on-one-server-but-not-another/#findComment-646384 Share on other sites More sharing options...
gazfocus Posted September 20, 2008 Author Share Posted September 20, 2008 Could you post the code? <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Rainbow Childcare</title> <style type="text/css"> <!-- body { font-family:Arial, Helvetica, sans-serif; font-weight: bold; color:#FFFFFF; } .bg { background-image: url(rainbow.jpg); background-repeat: no-repeat; background-position:center; height: 500px; } .contact { position:absolute; top:290px; left:29%; } --> </style></head> <body> <div class="bg" id="bg"> <div class="contact" id="contact"> <?php if ($_POST[viewed] !="yes") { echo "<form id=\"queryform\" name=\"queryform\" method=\"post\" action=\"$SERVER[php_SELF]\" onsubmit=\"return validate()\"> <table align=\"center\" width=\"500\"> <tr> <td> <p> <label>Name</label> </p> </td> <td align=\"left\"> <input type=\"text\" id=\"name\" name=\"name\" maxlength=\"30\" /> </td> <td> <p> <label>Telephone Number</label> </p> </td> <td align=\"left\"> <input type=\"text\" id=\"tel\" name=\"tel\" maxlength=\"11\" /> </td> </tr> <tr> <td> <p> <label>E-mail Address</label> </p> </td> <td align=\"left\"> <input type=\"text\" id=\"email\" name=\"email\" maxlength=\"30\" /> </td> <td> <p> <label>Please enter your query</label> </p> </td> <td align=\"left\"> <textarea name=\"query\" colspan=\"30\" rows=\"4\" id=\"query\"></textarea> </td> </tr> </table> <input name=\"viewed\" type=\"hidden\" value=\"yes\" /> <center><input name=\"submit\" type=\"submit\" value=\"Submit Query\" /></center> </form>"; } else { if(isset($_POST['submit'])) { $to = "[email protected]"; $subject = "Website Query"; $name = $_POST['name']; $tel = $_POST['tel']; $email = $_POST['email']; $query = $_POST['query']; $body = "From: " . $name . " Telephone Number: " . $tel . " E-mail Address: " . $email . " Query: " . $query; echo "<p class=\"center\"><br /> <br /> <br />Your query has been submitted and I will reply to you as soon as possible </p>"; mail($to, $subject, $body); echo "<meta http-equiv=\"REFRESH\" content=\"3;url=index.php\">"; } } ?></div></div> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/125074-solved-php-form-working-on-one-server-but-not-another/#findComment-646386 Share on other sites More sharing options...
waynew Posted September 20, 2008 Share Posted September 20, 2008 Well, $SERVER[php_SELF] should be $_SERVER[php_SELF] Quote Link to comment https://forums.phpfreaks.com/topic/125074-solved-php-form-working-on-one-server-but-not-another/#findComment-646389 Share on other sites More sharing options...
waynew Posted September 20, 2008 Share Posted September 20, 2008 Change: if ($_POST[viewed] !="yes") to if (isset($_POST['viewed']) && $_POST['viewed'] !="yes") Quote Link to comment https://forums.phpfreaks.com/topic/125074-solved-php-form-working-on-one-server-but-not-another/#findComment-646391 Share on other sites More sharing options...
wildteen88 Posted September 20, 2008 Share Posted September 20, 2008 These are not errors. Errors cause PHP to terminate script execution. The three notices displayed are easily fixed. Notice: Use of undefined constant viewed - assumed 'viewed' in E:\domains\r\rainbowchildcare.org.uk\user\htdocs\rainbow.php on line 32 This is caused by calling a key from an associative array without placing quotes around the key, eg $_POST[viewed] is incorrect it should be $_POST['viewed'] Notice: Undefined index: viewed in E:\domains\r\rainbowchildcare.org.uk\user\htdocs\rainbow.php on line 32 This is caused because PHP couldn't find the key (in this case 'viewed') within the $_POST array. To fix, change: if ($_POST[viewed] !="yes") to if (isset($_POST['viewed']) && $_POST['viewed'] !="yes") Notice: Undefined variable: SERVER in E:\domains\r\rainbowchildcare.org.uk\user\htdocs\rainbow.php on line 34 This caused because PHP couldn't find the variable $SERVER. I presume here you meant to use the $_SERVER superglobal. Quote Link to comment https://forums.phpfreaks.com/topic/125074-solved-php-form-working-on-one-server-but-not-another/#findComment-646392 Share on other sites More sharing options...
gazfocus Posted September 20, 2008 Author Share Posted September 20, 2008 Change: if ($_POST[viewed] !="yes") to if (isset($_POST['viewed']) && $_POST['viewed'] !="yes") Thanks for all your help, however, I now don't get any errors but nothing's displayed now (check www.rainbowchildcare.org.uk/rainbow.php) Ta Quote Link to comment https://forums.phpfreaks.com/topic/125074-solved-php-form-working-on-one-server-but-not-another/#findComment-646394 Share on other sites More sharing options...
waynew Posted September 20, 2008 Share Posted September 20, 2008 Try if (!isset($_POST['viewed'])) Quote Link to comment https://forums.phpfreaks.com/topic/125074-solved-php-form-working-on-one-server-but-not-another/#findComment-646398 Share on other sites More sharing options...
gazfocus Posted September 20, 2008 Author Share Posted September 20, 2008 Try if (!isset($_POST['viewed'])) Got my form back....with if (!isset($_POST['viewed']) && $_POST['viewed'] !="yes") but now I get this again Notice: Undefined index: viewed in E:\domains\r\rainbowchildcare.org.uk\user\htdocs\rainbow.php on line 32 p.s. the same happened when I put if (!isset($_POST['viewed'])) Quote Link to comment https://forums.phpfreaks.com/topic/125074-solved-php-form-working-on-one-server-but-not-another/#findComment-646402 Share on other sites More sharing options...
wildteen88 Posted September 20, 2008 Share Posted September 20, 2008 Use: if ((!isset($_POST['viewed'])) || (isset($_POST['viewed']) && $_POST['viewed'] !="yes")) Quote Link to comment https://forums.phpfreaks.com/topic/125074-solved-php-form-working-on-one-server-but-not-another/#findComment-646404 Share on other sites More sharing options...
gazfocus Posted September 20, 2008 Author Share Posted September 20, 2008 Use: if ((!isset($_POST['viewed'])) || (isset($_POST['viewed']) && $_POST['viewed'] !="yes")) Thanks, that worked a treat...now...When the form is submitted, I get the message saying the details have been sent (although it doesn't send it), but then I get Warning: mail() [function.mail]: "sendmail_from" not set in php.ini or custom "From:" header missing in E:\domains\r\rainbowchildcare.org.uk\user\htdocs\rainbow.php on line 93 Quote Link to comment https://forums.phpfreaks.com/topic/125074-solved-php-form-working-on-one-server-but-not-another/#findComment-646411 Share on other sites More sharing options...
wildteen88 Posted September 20, 2008 Share Posted September 20, 2008 the mail function requires 4 parameters - to, subject, body and headers. Change mail($to, $subject, $body); to $header = "From: ". $name . " <" . $email . ">\r\n" mail($to, $subject, $body, $header); Quote Link to comment https://forums.phpfreaks.com/topic/125074-solved-php-form-working-on-one-server-but-not-another/#findComment-646567 Share on other sites More sharing options...
gazfocus Posted September 24, 2008 Author Share Posted September 24, 2008 Thanks to everyone for all your help.. I'm still getting errors though: When I submit the form, I get: Warning: mail() [function.mail]: SMTP server response: 554 <[email protected]>: Recipient address rejected: Relay access denied in E:\domains\r\rainbowchildcare.org.uk\user\htdocs\index.php on line 93 please help lol Quote Link to comment https://forums.phpfreaks.com/topic/125074-solved-php-form-working-on-one-server-but-not-another/#findComment-649595 Share on other sites More sharing options...
thesaleboat Posted September 24, 2008 Share Posted September 24, 2008 Contact your ISP host, we had this same problem but it was only that it would not send mail to us if we were trying to send it from our website, but everyone else could send it. It has something to do with you trying to send email from your own email logged into your own account. Quote Link to comment https://forums.phpfreaks.com/topic/125074-solved-php-form-working-on-one-server-but-not-another/#findComment-649600 Share on other sites More sharing options...
gazfocus Posted September 24, 2008 Author Share Posted September 24, 2008 Contact your ISP host, we had this same problem but it was only that it would not send mail to us if we were trying to send it from our website, but everyone else could send it. It has something to do with you trying to send email from your own email logged into your own account. Thanks... changed the email address and it works fine Quote Link to comment https://forums.phpfreaks.com/topic/125074-solved-php-form-working-on-one-server-but-not-another/#findComment-649620 Share on other sites More sharing options...
thesaleboat Posted September 24, 2008 Share Posted September 24, 2008 no problem Quote Link to comment https://forums.phpfreaks.com/topic/125074-solved-php-form-working-on-one-server-but-not-another/#findComment-649621 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.