Jump to content

[SOLVED] PHP form working on one server but not another


Recommended Posts

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

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

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>

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.

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

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']))

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

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); 

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

 

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. 

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 :)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.